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

html_table and database data

 
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 -> Plugins
View previous topic :: View next topic  
Author Message
gawan
Smarty Rookie


Joined: 29 Apr 2003
Posts: 9

PostPosted: Tue Apr 29, 2003 10:12 am    Post subject: html_table and database data Reply with quote

How can I use html_table plugin to loop through database query results with several fields of data? The result set comes as an array on row objects, so it would be one dimensional.
Back to top
View user's profile Send private message
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Tue Apr 29, 2003 10:28 am    Post subject: Reply with quote

I dont think its possible with the default html_table function you would have to convert it to an array with just the data in it and force the number of columns to be the number returned so it will wrap. Something like

[php:1:a4bece7f19]$data = array();

$vars = get_object_vars($result[0]);
$cols = count($vars);

foreach($result as $object) {
$vars = get_object_vars($object);
foreach($vars as $key => $value) {
$data[] = $value;
}
}
$smarty->assign("data", $data);
$smarty->assign("cols", $cols);[/php:1:a4bece7f19]

then in your template

Code:
{html_table loop=$data cols=$cols}


I didnt test that so it might have a bug in it but something like that should work
_________________
"Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane
Back to top
View user's profile Send private message Visit poster's website
gawan
Smarty Rookie


Joined: 29 Apr 2003
Posts: 9

PostPosted: Tue Apr 29, 2003 11:36 am    Post subject: Reply with quote

Thanks, I'll try this

gawan
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 -> Plugins 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