Jump to content

First time trying JOIN - fetch_array() expects parameter 1 to be resource


Nysaan

Recommended Posts

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"

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.