simonsays Posted May 1, 2007 Share Posted May 1, 2007 Hello! I am trying to make a script that is capable of getting and displaying (using Smarty) any database table. Something like that: function getTableAll ($table) { $data = array(); $sql = pg_query("SELECT * FROM $table"); while ($row = pg_fetch_array($sql)){ array_push($data, $row); } return $data; } function getFields ($table) { $fields = array(); $sql = pg_query("SELECT * FROM $table"); $i = pg_num_fields ($sql); $j = 0; while ($j < $i) { $fields[] = pg_field_name ($sql, $j); $j++; } return $fields; } $smarty->assign('data', $data); $smarty->assign('fields', $fields); The problems come when I try to display table using Smarty, because the template engine does not have any FOR loop or something like that. {section name=a loop=$fields} <td bgcolor="#1A2F4A"><p class='main'>{$fields[a]}</p></td> {/section} {section name=b loop=$data} </tr> ????? <tr> {/section} Can anyone help? Link to comment https://forums.phpfreaks.com/topic/49491-solved-php-script-to-get-any-database-table/ Share on other sites More sharing options...
simonsays Posted May 1, 2007 Author Share Posted May 1, 2007 thanks! the problem is solved Link to comment https://forums.phpfreaks.com/topic/49491-solved-php-script-to-get-any-database-table/#findComment-242595 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.