Jump to content

[SOLVED] PHP Script to get any database table


simonsays

Recommended Posts

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.