I have written a function to print database table to an array like this
$db_array=
Array(
ID=>1,
PARENTID =>1,
TITLE => LIPSUM,
TEXT =>LIPSUM
)
My function is:
function dbToArray($table)
{
$allArrays =array();
$query = mysql_query("SELECT * FROM $table");
$dbRow = mysql_fetch_array($query);
for ($i=0; $i<count($dbRow) ; $i++)
{
$allArrays[$i] = $dbRow;
}
$txt .='<pre>';
$txt .= print_r($allArrays);
$txt .= '</pre>';
return $txt;
}
Anything wrong in my function. Any help is appreciated about my problem. Thanks in advance
Im not sure your function will get all the rows returned by the database.
mysql_fetch_array()returns only one row. So the for loop is pretty pointless.Instead you should something like this instead of the for loop.
by the way if you still want to use the for loop you could try something like this.
But what would be the point?the while loop works perfectly for this.