Maknib Posted February 15, 2011 Share Posted February 15, 2011 just trying to see if i have this right in my head here.. if i have a page that has a topic on it and many replies, the tables would look like this.. would this be the right code to pull out the topic AND all responses for say. www.mysite.com/view?id=1 $topic = 'SELECT * from topics where id = $id' $replies = 'SELECT * from replies where replies.topic_id = $id' Quote Link to comment https://forums.phpfreaks.com/topic/227707-tables-i-think-i-have-it-mysql/ Share on other sites More sharing options...
Ninjakreborn Posted February 15, 2011 Share Posted February 15, 2011 Essentially, yes. It would be much more efficient if you set it up as a join instead. Something like (untested) "SELECT * FROM topics LEFT JOIN replies ON replies.topic_id = topics.ID" Quote Link to comment https://forums.phpfreaks.com/topic/227707-tables-i-think-i-have-it-mysql/#findComment-1174385 Share on other sites More sharing options...
Maknib Posted February 15, 2011 Author Share Posted February 15, 2011 Essentially, yes. It would be much more efficient if you set it up as a join instead. Something like (untested) "SELECT * FROM topics LEFT JOIN replies ON replies.topic_id = topics.ID" thanks i'll look into it havn't looked into JOIN so LEFT JOIN and ON is foreign to me Quote Link to comment https://forums.phpfreaks.com/topic/227707-tables-i-think-i-have-it-mysql/#findComment-1174391 Share on other sites More sharing options...
Ninjakreborn Posted February 15, 2011 Share Posted February 15, 2011 http://www.wellho.net/mouth/158_MySQL-LEFT-JOIN-and-RIGHT-JOIN-INNER-JOIN-and-OUTER-JOIN. http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html The second link will be the most beneficial in learning the basics of Joins. Quote Link to comment https://forums.phpfreaks.com/topic/227707-tables-i-think-i-have-it-mysql/#findComment-1174393 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.