|
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 |
gawan Smarty Rookie
Joined: 29 Apr 2003 Posts: 9
|
Posted: Tue Apr 29, 2003 10:12 am Post subject: html_table and database data |
|
|
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 |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Tue Apr 29, 2003 10:28 am Post subject: |
|
|
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 |
|
gawan Smarty Rookie
Joined: 29 Apr 2003 Posts: 9
|
Posted: Tue Apr 29, 2003 11:36 am Post subject: |
|
|
Thanks, I'll try this
gawan |
|
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
|