Jump to content

Recommended Posts

Hi guys, I never learnt joins, and this is what my code looks like as a result, Can someone just show me how to convert the following from 2 queries to one? It is a blog post and the second query is getting an author I have shortened it for convenience. 

 

Thanks in advance.

$getBlogs = mysql_query("SELECT * FROM blogs WHERE blogStatus='1'", $retreat);
		while($row = mysql_fetch_array($getBlogs)){
			$blogID = $row['blogID'];
			$authurID = $row['authurID'];
		}

		$getAuthor = mysql_query("SELECT * FROM blog_authurs WHERE authurID='$blogAuthur' LIMIT 1", $retreat);
			while($row = mysql_fetch_array($getAuthor)){
				$authurName = $row['authurName'];
			}
Link to comment
https://forums.phpfreaks.com/topic/290812-php-joins/
Share on other sites

So you are getting the authurID from the first query and using it in the second query?  OR, are you using the variable $blogAuthur to populate the second query?  I will go on the assumption that it is the former.

 

"SELECT
   b.blogID, a.authurName
 FROM
   blogs AS b
 JOIN
   blog_authurs AS a
 ON
   b.authurID = a.authurID
 WHERE
   blogStatus = 1
"
Link to comment
https://forums.phpfreaks.com/topic/290812-php-joins/#findComment-1489702
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.