Say I have a query to get all information in a particular database that could have different schemas.
For example, I may have:
DB1 with [id] [blah] [shibby] &
DB2 with [id] [yadda] [etc] [andsoforth]
Then I run a query which needs to return:
A) the field names into a table header
B) the results into a table cell
The query would be generated from a form via post in order to set some variables to determine which database to get the information from.
The below will get me the column names, but I then need to populate the remainder with the actual results.
echo "<table>";
echo "<tr>";
$qColumnNames = mysql_query("SHOW COLUMNS FROM ".$db) or die("mysql error");
$numColumns = mysql_num_rows($qColumnNames);
$x = 0;
while ($x < $numColumns)
{
$colname = mysql_fetch_row($qColumnNames);
$col[$colname[0]] = $colname[0];
$x++;
}
foreach($col as $key){
echo "<th>$key</th>";
}
echo "</tr>";
echo "</table>";