Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

My Problem :S

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
ulast
Smarty Rookie


Joined: 01 Apr 2013
Posts: 11

PostPosted: Thu Jul 18, 2013 9:04 am    Post subject: My Problem :S Reply with quote

Code:
$types = $db->get_results("SELECT * FROM types WHERE dil='1'");
echo '<ul>';
foreach($types AS $type){
   $groups = $db->get_results("SELECT * FROM urunler WHERE tur_kod='". $type->tur_kod ."' GROUP by kat_id");
   echo "<li>". $tur->tur ."<ul>";
   foreach($groups AS $group){
   $cat = $db->get_row("SELECT * FROM kategori WHERE id='". $group->kat_id ."'");
   echo "<li>". $cat->baslik .'</li>';
   }
echo '</ul></li>';
}
echo '</ul>';


How do write in smarty? Question
Back to top
View user's profile Send private message
ulast
Smarty Rookie


Joined: 01 Apr 2013
Posts: 11

PostPosted: Thu Jul 18, 2013 9:45 am    Post subject: Reply with quote

pls help me Sad
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Jul 18, 2013 1:35 pm    Post subject: Reply with quote

First assemble the data in a tree structure:

Code:

   $types = $db->get_results("SELECT * FROM types WHERE dil='1'");
   foreach($types as $tkey=>$type) {
        $groups = $db->get_results("SELECT * FROM urunler WHERE tur_kod='". $type->tur_kod ."' GROUP by kat_id");
        foreach($groups as $gkey => $group) {
            $cat = $db->get_row("SELECT * FROM kategori WHERE id='". $group->kat_id ."'");
            $groups[$gkey]['cat'] = $cat;
        }
        $types[$tkey]['groups'] = $groups;
   }
$smarty->assign('types', $types);
$smarty->assign('tur', $tur); // this must exist from elsewhere?


Then loop over the vars in the template and add your html:

Code:
<ul>
{foreach $types as $type}
   <li>{$tur->tur}</li>
   {foreach $type.groups as $group} 
     <li>{$group.cat->baslik}</li>
   {/foreach}
   </ul></li>
{/foreach}
</ul>



of course this is untested, you may have to adjust somethings. but that is a start.
Back to top
View user's profile Send private message Visit poster's website
ulast
Smarty Rookie


Joined: 01 Apr 2013
Posts: 11

PostPosted: Thu Jul 18, 2013 3:26 pm    Post subject: Reply with quote

Code:
Fatal error: Cannot use object of type stdClass as array in /


this error show in smarty and show in php
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Jul 18, 2013 3:29 pm    Post subject: Reply with quote

Quote:
of course this is untested, you may have to adjust somethings. but that is a start.


debug your code. somewhere an object is being used as an array. adjust accordingly.

In the template, foo.bar is array access, foo->bar is object access.
Back to top
View user's profile Send private message Visit poster's website
ulast
Smarty Rookie


Joined: 01 Apr 2013
Posts: 11

PostPosted: Thu Jul 18, 2013 3:38 pm    Post subject: Reply with quote

Code:
$turler = $db->get_results("SELECT * FROM turler WHERE dil='1'");
foreach($turler AS $ktur => $vtur){
   
   $urun_grup = $db->get_results("SELECT * FROM urunler WHERE tur_kod='". $vtur->tur_kod ."' GROUP by kat_id");
   
   foreach($urun_grup AS $kurun => $vurun){
   
   $kategori = $db->get_row("SELECT * FROM kategori WHERE id='". $vurun->kat_id ."'");
   $urun_grup[$kurun]->cat = $kategori;   
   }
   $turler[$ktur]->groups = $urun_grup;
}


Code:
{foreach $turler as $tur}
<li>{$tur->tur}<ul>
{foreach $tur->groups as $group}
<li>{$group->cat->baslik}</li>
{/foreach}
</ul></li>
{/foreach}


{$tur->tur} working but {$group->cat->baslik} not working
Back to top
View user's profile Send private message
ulast
Smarty Rookie


Joined: 01 Apr 2013
Posts: 11

PostPosted: Thu Jul 18, 2013 4:00 pm    Post subject: Reply with quote

okey okey okey Idea now working sorry Smile thanks my friend!!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP