Nysaan Posted December 14, 2011 Share Posted December 14, 2011 Hi. It's the first time i try JOIN in MySQL integrated with PHP. I'm also a newbie @PHP so please bare with me... mysql_select_db("dbnamehere", $con); $result = mysql_query(" SELECT * FROM blogg JOIN blogg_categories ON (blogg.category=blogg_categories.id) ORDER BY id DESC"); while($row = mysql_fetch_array($result)) { I keep getting this error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in xxxxxxxxxxxxxxxxxx on line49. Line 49 is "While" Quote Link to comment https://forums.phpfreaks.com/topic/253141-first-time-trying-join-fetch_array-expects-parameter-1-to-be-resource/ Share on other sites More sharing options...
sandeep529 Posted December 14, 2011 Share Posted December 14, 2011 hi, Seems mysql_query is returning an error, i mean a false value to $result. Just try removing that join and give a simple query like "SELECT * FROM blogg" and see if it works. If it works, try replacing ON (blogg.category=blogg_categories.id) with ON (`blogg`.`category`=`blogg_categories`.`id`) those are backticks not single quotes by the way. Regards, Sandeep. Quote Link to comment https://forums.phpfreaks.com/topic/253141-first-time-trying-join-fetch_array-expects-parameter-1-to-be-resource/#findComment-1297748 Share on other sites More sharing options...
Nysaan Posted December 14, 2011 Author Share Posted December 14, 2011 It works using a simply query. I've tried that before and I did it again after reading your post. I tried the code you gave me: ON (`blogg`.`category`=`blogg_categories`.`id`) but that didn't work either. But after looking in my database I relized my misstake pretty quick. Since I've got ID in both tables (blogg and blogg.categories) it didn't know wich one to order by. So I changed: ORDER BY id DESC to ORDER BY blogg.id DESC And now it works Quote Link to comment https://forums.phpfreaks.com/topic/253141-first-time-trying-join-fetch_array-expects-parameter-1-to-be-resource/#findComment-1297750 Share on other sites More sharing options...
sandeep529 Posted December 14, 2011 Share Posted December 14, 2011 Sorry about that, I should have told you to use mysql_error() to get the last mysql error like mysql_query(" SELECT * FROM blogg JOIN blogg_categories ON (blogg.category=blogg_categories.id) ORDER BY id DESC") or die( mysql_error() ); regards, sandeep. Quote Link to comment https://forums.phpfreaks.com/topic/253141-first-time-trying-join-fetch_array-expects-parameter-1-to-be-resource/#findComment-1297763 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.