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

replace foreach with something

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
smartybug
Smarty Rookie


Joined: 18 Jan 2010
Posts: 14

PostPosted: Sat Oct 09, 2010 12:31 pm    Post subject: replace foreach with something Reply with quote

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
View user's profile Send private message
smartybug
Smarty Rookie


Joined: 18 Jan 2010
Posts: 14

PostPosted: Sat Oct 09, 2010 8:38 pm    Post subject: Reply with quote

Nobody knows?
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Sun Oct 10, 2010 12:37 am    Post subject: Reply with quote

so, you're saying instead of this:

Code:
{foreach from=$DB_WEB item="row_obj"}{$row_obj->title}{/foreach}


just put this?
Code:
{$DB_WEB.title}


no, you can't do that. {$DB_WEB.title} is the syntax for the 'title' element of the $DB_WEB array.
Back to top
View user's profile Send private message
smartybug
Smarty Rookie


Joined: 18 Jan 2010
Posts: 14

PostPosted: Sun Oct 10, 2010 7:46 am    Post subject: Reply with quote

But if I use:
Code:
{$DB_WEB.title}

It does not do anything. Result of this code is empty space.
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Sun Oct 10, 2010 1:17 pm    Post subject: Reply with quote

smartybug wrote:
But if I use:
Code:
{$DB_WEB.title}

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

Code:

{$DB_WEB.title}


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
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 -> Feature Requests 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