l3rodey Posted September 2, 2014 Share Posted September 2, 2014 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']; } Quote Link to comment Share on other sites More sharing options...
jcbones Posted September 3, 2014 Share Posted September 3, 2014 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 " Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 3, 2014 Share Posted September 3, 2014 Since one doesn't 'do' a join in PHP, perhaps you should ask in an SQL forum instead of a PHP one? Quote Link to comment Share on other sites More sharing options...
CroNiX Posted September 3, 2014 Share Posted September 3, 2014 Sure it does Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 3, 2014 Share Posted September 3, 2014 Sure it does On a more serious note: No - it doesn't. Quote Link to comment 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.