I have a database with some tables and columns.
I want to create a multidimensional array in PHP to store these values.
$tableData = array(array()); // I try to set up the multidimensional array.
/* 1: Get Table Names (works fine) */
$result = mysql_query("SHOW TABLES FROM myDatabase");
$i=0;
while ($row = mysql_fetch_row($result))
{
// Push the table name into the PHP array
array_push($tableData, $row[0]);
}
/* 2: Columns */
for ($i = 1; $i < count($tableNames); $i++)
{
$result = mysql_query("SHOW COLUMNS FROM $tableData[$i]");
while ($row = mysql_fetch_assoc($result))
{
array_push($tableData[$i], $row); // ** ERROR THROWN: first argument must be an array ** //
}
}
How can I do this? I feel like this should be simple, but I’ve spent the last 4 hours banging my head on my keyboard and google trying to figure it out… plenty of tutorial on putting a multidimensional array into a SQL, but not much for the other way around!
Thanks!
you don’t need to array(array()) to set up a multidimensional array. just push other array as a value.
try this: