Jump to content

Printing out a table from a query


ArizonaJohn

Recommended Posts

Hello,

 

I am trying to print out the result of the code below as a table, but the line with "while ($row2 = mysql_fetch_array($result))" gives the error statement: "mysql_fetch_array(): supplied argument is not a valid MySQL result resource".  Any idea how I can get it to work?

 

Thanks in advance,

 

John

 

mysql_connect("mysqlv10", "username", "password") or die(mysql_error());
mysql_select_db("bookfeather") or die(mysql_error());


$result = mysql_query("SHOW TABLES");
$tables = array();
while ($row1 = mysql_fetch_assoc($result)) {
    $tables[] = $row1["Tables_in_bookfeather"];

}

$subQuery = implode(" UNION ALL SELECT site, votes_up FROM ",$tables);
// Create one query that gets the data you need
$sqlStr = "SELECT site, sum(votes_up) 
    		FROM (
    		".$subQuery." ) subQuery
    	   GROUP BY site ORDER BY sum(votes_up) DESC LIMIT 25";
$result = mysql_query($sqlStr);

echo "<table>";
while ($row2 = mysql_fetch_array($result))
{
  echo '<tr><td>'.$row2['site'].'</td></tr>';
}
echo "</table>";

Link to comment
https://forums.phpfreaks.com/topic/169025-printing-out-a-table-from-a-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.