php - Mysql get column names then results -


say have query information in particular database have different schemas.

for example, may have:
db1 [id] [blah] [shibby] &
db2 [id] [yadda] [etc] [andsoforth]

then run query needs return:
a) field names table header
b) results table cell

the query generated form via post in order set variables determine database information from.

the below me column names, need populate remainder actual results.

echo "<table>"; echo "<tr>"; $qcolumnnames = mysql_query("show columns ".$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 $key){     echo "<th>$key</th>"; } echo "</tr>"; echo "</table>"; 

you database, mean fields table? have first part - get column names - , implode string array , use in select query:

$query = "select ".implode(",", $col)." [tablename] ..."; 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

monitor web browser programmatically in Android? -

c# - Using multiple datasets in RDLC -