|
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 |
smartybug Smarty Rookie
Joined: 18 Jan 2010 Posts: 14
|
Posted: Sat Oct 09, 2010 12:31 pm Post subject: replace foreach with something |
|
|
I take data with:
Code: | $web = $db->get_results("SELECT * FROM config"); |
In config is title, subname, theme......
Code: | $Smarty->assign('DB_WEB', $web); |
I have in index.tpl:
Code: |
{foreach from=$DB_WEB item="row_obj"}{$row_obj->title}{/foreach} |
Can i replace it with something? For example {$DB_WEB.title} ???? |
|
Back to top |
|
smartybug Smarty Rookie
Joined: 18 Jan 2010 Posts: 14
|
Posted: Sat Oct 09, 2010 8:38 pm Post subject: |
|
|
Nobody knows? |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Sun Oct 10, 2010 12:37 am Post subject: |
|
|
so, you're saying instead of this:
Code: | {foreach from=$DB_WEB item="row_obj"}{$row_obj->title}{/foreach} |
just put this?
no, you can't do that. {$DB_WEB.title} is the syntax for the 'title' element of the $DB_WEB array. |
|
Back to top |
|
smartybug Smarty Rookie
Joined: 18 Jan 2010 Posts: 14
|
Posted: Sun Oct 10, 2010 7:46 am Post subject: |
|
|
But if I use:
It does not do anything. Result of this code is empty space. |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Sun Oct 10, 2010 1:17 pm Post subject: |
|
|
smartybug wrote: | But if I use:
It does not do anything. Result of this code is empty space. |
Correct, that's because there is no 'title' index of the $DB_WEB array. $DB_WEB is numerically indexed like 0,1,2...
You need to learn more about arrays and array syntax, and foreach loops and how those work if you don't understand the difference between
and
Code: |
{foreach from=$DB_WEB item="row_obj"}{$row_obj->title}{/foreach} |
Is there a purpose for changing the code? What are you trying to accomplish? |
|
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
|