xyph Posted July 19, 2012 Share Posted July 19, 2012 Here's what works on my machine <?php $db = new MySQLi('localhost','root','','db'); $author_id = 19; $query = "SELECT DISTINCT cat.varCategory FROM tarticles art LEFT JOIN tcategories cat ON art.intCategory = cat.intID WHERE art.intAuthorId = $author_id AND art.intStatus = 1"; $result = $db->query($query); if( $result == FALSE ) { echo "Query failed! Query: $query <br> Error: $db->error"; } else { while( $row = $result->fetch_assoc() ) { echo "{$row['varCategory']}<br>"; } } ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted July 19, 2012 Share Posted July 19, 2012 I missed the word "ON" from the 4th line SELECT a.intAuthorId, c.varCategory, p.varCategory as parent FROM tarticles a INNER JOIN tcategories c ON a.intCategory = c.intId LEFT JOIN tcategories p ON c.intParentId = p.intId Quote Link to comment Share on other sites More sharing options...
xtrax Posted July 19, 2012 Author Share Posted July 19, 2012 Ok i tried xyph code but it stops the page from loading... Nothing in the error logs or on the page to even indicate there is an error... We are using the following MySQL 5.0.95-community in cPanel and PHP Version 5.3.13 would this have anything to do with it?? xtrax Quote Link to comment Share on other sites More sharing options...
xyph Posted July 19, 2012 Share Posted July 19, 2012 Wait a sec, updating the code. Quote Link to comment Share on other sites More sharing options...
xtrax Posted July 19, 2012 Author Share Posted July 19, 2012 Never mind I got it xyph !!!!!!!!!!!!!!!!!!!!! I made some minor changes to the following and its now working I am also caching the results to reduce the load This is what I came up with $article_topics = $d->fetch("SELECT DISTINCT (cat.varCategory) FROM tarticles art LEFT JOIN tcategories cat ON art.intCategory = cat.intID WHERE art.intAuthorId = '$author_ID' AND art.intStatus = '1' LIMIT 0 , 30", "daily", "auth_topics".$author_ID.".af"); if($article_topics){ foreach($article_topics as $dtopic){ $catsname = $dtopic['varCategory']; echo "<strong>".$catsname."</strong>, "; } } Where can I make a donation and what would you like for payment! xtrax Quote Link to comment Share on other sites More sharing options...
xtrax Posted July 19, 2012 Author Share Posted July 19, 2012 Donations made and thank you for all your help! This is trully a great forum! Xtrax Quote Link to comment Share on other sites More sharing options...
xyph Posted July 19, 2012 Share Posted July 19, 2012 Is this what you wanted as well? SELECT DISTINCT cat.varCategory, cat.intParentId, art.intCategory FROM tarticles art LEFT JOIN tcategories cat ON art.intCategory = cat.intID WHERE art.intAuthorId = 19 Alternately, you may have wanted SELECT cat.varCategory, cat.intParentId, art.intCategory FROM tarticles art LEFT JOIN tcategories cat ON art.intCategory = cat.intID WHERE art.intAuthorId = 19 GROUP BY cat.varCategory Though, in this case, those two queries may return the exact same results. Quote Link to comment Share on other sites More sharing options...
xtrax Posted July 19, 2012 Author Share Posted July 19, 2012 That did it, viola now my cats are linked to the appropriate categories.... Thanks again and have a great night! xtrax 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.