|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
ulast Smarty Rookie
Joined: 01 Apr 2013 Posts: 11
|
Posted: Thu Jul 18, 2013 9:04 am Post subject: My Problem :S |
|
|
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? |
|
Back to top |
|
ulast Smarty Rookie
Joined: 01 Apr 2013 Posts: 11
|
Posted: Thu Jul 18, 2013 9:45 am Post subject: |
|
|
pls help me |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jul 18, 2013 1:35 pm Post subject: |
|
|
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 |
|
ulast Smarty Rookie
Joined: 01 Apr 2013 Posts: 11
|
Posted: Thu Jul 18, 2013 3:26 pm Post subject: |
|
|
Code: | Fatal error: Cannot use object of type stdClass as array in / |
this error show in smarty and show in php |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jul 18, 2013 3:29 pm Post subject: |
|
|
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 |
|
ulast Smarty Rookie
Joined: 01 Apr 2013 Posts: 11
|
Posted: Thu Jul 18, 2013 3:38 pm Post subject: |
|
|
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 |
|
ulast Smarty Rookie
Joined: 01 Apr 2013 Posts: 11
|
Posted: Thu Jul 18, 2013 4:00 pm Post subject: |
|
|
okey okey okey now working sorry thanks my friend!! |
|
Back to top |
|
|
|
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
|