Mod-Jay Posted September 4, 2010 Share Posted September 4, 2010 Error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\Users\cory\Desktop\xampp\htdocs\Starter Kit(2)\admincp\pages\news.php on line 40 Code: <?php $result = mysql_query("SELECT * FROM blog ORDER BY desc"); //the while loop while($r=mysql_fetch_array($result)) {$id=$r["ID"];$name=$r["name"];$desc=$r["descr"];$date=$r["date"];echo "<tr><td>News Name: $name</td><td>News Desc: $desc</td><td>Date Posted: $date</td><td><a href='edit.php'>Edit</a></td><td><a href='news.php?action=delete&id=$id'>Delete $name</a></td></tr>";}?> Line 40: while($r=mysql_fetch_array($result)) Quote Link to comment https://forums.phpfreaks.com/topic/212479-another-error/ Share on other sites More sharing options...
wildteen88 Posted September 4, 2010 Share Posted September 4, 2010 This usually means there was a problem with your query. Change $result = mysql_query("SELECT * FROM blog ORDER BY desc"); to $result = mysql_query("SELECT * FROM blog ORDER BY desc") or trigger_error('Query Error: ' . mysql_error(), E_USER_ERROR); What error is shown now? Quote Link to comment https://forums.phpfreaks.com/topic/212479-another-error/#findComment-1107041 Share on other sites More sharing options...
Mod-Jay Posted September 4, 2010 Author Share Posted September 4, 2010 Thats it Fatal error: Query Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc' at line 1 in C:\Users\cory\Desktop\xampp\htdocs\Starter Kit(2)\admincp\pages\news.php on line 38 Line 38 Is the Query. Wild Gave me Quote Link to comment https://forums.phpfreaks.com/topic/212479-another-error/#findComment-1107042 Share on other sites More sharing options...
wildteen88 Posted September 4, 2010 Share Posted September 4, 2010 desc is a mysql reserved keyword. Either rename your column to description (I guess that is what desc is short for) or wrap it in back ticks, eg`desc` Quote Link to comment https://forums.phpfreaks.com/topic/212479-another-error/#findComment-1107044 Share on other sites More sharing options...
Mod-Jay Posted September 4, 2010 Author Share Posted September 4, 2010 actully i thought it was to reorder the ids Quote Link to comment https://forums.phpfreaks.com/topic/212479-another-error/#findComment-1107045 Share on other sites More sharing options...
trq Posted September 4, 2010 Share Posted September 4, 2010 actully i thought it was to reorder the ids That would be.... SELECT * FROM blog ORDER BY id DESC Quote Link to comment https://forums.phpfreaks.com/topic/212479-another-error/#findComment-1107047 Share on other sites More sharing options...
Mod-Jay Posted September 4, 2010 Author Share Posted September 4, 2010 Ahhh Thanks Quote Link to comment https://forums.phpfreaks.com/topic/212479-another-error/#findComment-1107048 Share on other sites More sharing options...
wildteen88 Posted September 4, 2010 Share Posted September 4, 2010 Then you need to specify the field to order the results by. If its the id field then your query should be SELECT * FROM blog ORDER BY id DESC That will order the results by the id field in descending order (eg 5, 4, 3, 2, 1). To order in ascending order (eg 1, 2, 3, 4, 5 etc) you'd change DESC to ASC Quote Link to comment https://forums.phpfreaks.com/topic/212479-another-error/#findComment-1107049 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.