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

mysql_fetch_assoc and section

 
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
gdboling
Smarty Rookie


Joined: 20 Feb 2004
Posts: 31

PostPosted: Fri May 20, 2005 9:18 pm    Post subject: mysql_fetch_assoc and section Reply with quote

Can someone tell me why this isn't working.

Code:

$result = mysql_query("select * from t_category", $pnp);
$results = array();   
while($row = mysql_fetch_assoc($result)){
   $results[] = $row;
}   
   
$results = mysql_fetch_assoc($result);
$page->assign('results', $results);
$page->display('view_items.tpl');


Code:

<table border="1">
{section name=item loop=$results}
   <tr><td>
   {$results[item].description}
   </td></tr>
{/section}
</table>


I don't get anything in the {section}. I know it is pulling the data correctly because if I do the following in my php

echo $results[0]['description']; (looping over this of course)

I get the values I expect. It's just not working with section in my template.

Thanks.
_________________
Gregg
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Fri May 20, 2005 9:21 pm    Post subject: Reply with quote

This might be part of the problem:

Code:
while($row = mysql_fetch_assoc($result)){
   $results[] = $row;
}   
   
$results = mysql_fetch_assoc($result);



You loop through and assemble the $results array, then promptly overwrite it after the loop.
Back to top
View user's profile Send private message Visit poster's website
gdboling
Smarty Rookie


Joined: 20 Feb 2004
Posts: 31

PostPosted: Fri May 20, 2005 9:22 pm    Post subject: Reply with quote

mohrt wrote:
This might be part of the problem:

Code:
while($row = mysql_fetch_assoc($result)){
   $results[] = $row;
}   
   
$results = mysql_fetch_assoc($result);



You loop through and assemble the $results array, then promptly overwrite it after the loop.


DOH! Crap. Thanks.
_________________
Gregg
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