Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

mysql_fetch_assoc and section

 
Post new topic   Reply to topic    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:   
Post new topic   Reply to topic    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