yogen Posted July 30, 2011 Share Posted July 30, 2011 <?php include"scripts/connect_to_mysql.php"; $id = ""; $thought = ""; $thoughts = '<table border="0" align="center" cellpadding="4"> <tr> '; $sql = mysql_query("SELECT * FROM thoughts ORDER BY DESC LIMIT 1"); while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $thought = $row["thoughts"]; $thoughts .= '<td><div align="center" style="font-family: Arial, Helvetica, sans-serif;"><font size="-2">' . $thought . '</font><br /></td>'; } $thoughts .= ' </tr> </table> '; ?> Quote Link to comment https://forums.phpfreaks.com/topic/243335-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource/ Share on other sites More sharing options...
QuickOldCar Posted July 31, 2011 Share Posted July 31, 2011 try this, I'm guessing thoughts is not the table name. See what the error reads. <?php include"scripts/connect_to_mysql.php"; $id = ""; $thought = ""; $thoughts = '<table border="0" align="center" cellpadding="4"> <tr> '; $sql = mysql_query("SELECT * FROM thoughts ORDER BY DESC LIMIT 1") or die ('Error: '.mysql_error ()); while($row = mysql_fetch_array($sql)){ $id = $row['id']; $thought = $row['thoughts']; $thoughts .= '<td><div align="center" style="font-family: Arial, Helvetica, sans-serif;"><font size="-2">' . $thought . '</font><br /></td>'; } $thoughts .= ' </tr> </table> '; ?> Quote Link to comment https://forums.phpfreaks.com/topic/243335-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-1249614 Share on other sites More sharing options...
trq Posted July 31, 2011 Share Posted July 31, 2011 You should always check your queries succeed and return results before using them. The typical syntax is: $sql = "SELECT foo FROM bar"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // $result is now good to use } else { // no results returned - handle error } } else { // query failed - handle error } I would watch your variable naming conventions as well. mysql_query() does not return SQL, it returns a result set or false. Quote Link to comment https://forums.phpfreaks.com/topic/243335-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-1249615 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.