ArizonaJohn Posted August 6, 2009 Share Posted August 6, 2009 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 More sharing options...
machiavelli1079 Posted August 6, 2009 Share Posted August 6, 2009 In my experience this error occurs when either no results are returned or there was an error in the sql statement. Try running your query from command line or mysql admin tool if possible and see if it throws an error. Link to comment https://forums.phpfreaks.com/topic/169025-printing-out-a-table-from-a-query/#findComment-891876 Share on other sites More sharing options...
Mardoxx Posted August 6, 2009 Share Posted August 6, 2009 ".$subQuery." ) subQuery ".$subQuery." ) subQuery <<< is that meant to be there? Link to comment https://forums.phpfreaks.com/topic/169025-printing-out-a-table-from-a-query/#findComment-891879 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.