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
Seems like you are trying to print a table (not a database)
function printTable($table){
$allRows = array();
$query = mysql_query("SELECT * FROM $table");
while($row = mysql_fetch_array($query)){
$allArrays[] = $row;
}
$txt ='<pre>';
$txt .= print_r($allRows, true);
$txt .= '</pre>';
echo $txt;
return $txt;
}
(Edit: fixed missing second parameter in print_r)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With