SkyRanger Posted March 16, 2012 Share Posted March 16, 2012 Not sure if it is because it is too early in the morning but I am having a problem. $mpid = # $query = "SELECT table1.title, table2.* ". "FROM table1, table2 ". "WHERE table1.mpid = table2.mpid"; How do I only show the info from the 2 tables where mpid=# Quote Link to comment https://forums.phpfreaks.com/topic/259059-join/ Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 Something like SELECT t1.title, t2.* FROM table1 AS t1 JOIN table2 AS t2 ON t2.mpid = t1.mpid Quote Link to comment https://forums.phpfreaks.com/topic/259059-join/#findComment-1328057 Share on other sites More sharing options...
SkyRanger Posted March 16, 2012 Author Share Posted March 16, 2012 ok, will that only pull that data and display on the page where $mpid = #. for example mpid = 2 so only anything in the two tables that have a mpid of 2 will be displayed? The reason why I ask is that I am learning on the fly and I don't see where it would pull the mpid that somebody would be requesting. Quote Link to comment https://forums.phpfreaks.com/topic/259059-join/#findComment-1328058 Share on other sites More sharing options...
dmikester1 Posted March 16, 2012 Share Posted March 16, 2012 Adding to scootsah's code: SELECT t1.title, t2.* FROM table1 AS t1 JOIN table2 AS t2 ON t2.mpid = t1.mpid WHERE t1.mpid = '2' BTW, this is a MySQL question, not a PHP question. Quote Link to comment https://forums.phpfreaks.com/topic/259059-join/#findComment-1328059 Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 You can add a where clause for the first table, and then the JOINed table should only pull results based on what the first table's mpid matches. SELECT t1.title, t2.* FROM table1 AS t1 JOIN table2 AS t2 ON t2.mpid = t1.mpid WHERE t1.mpid = '$mpid' Quote Link to comment https://forums.phpfreaks.com/topic/259059-join/#findComment-1328060 Share on other sites More sharing options...
SkyRanger Posted March 16, 2012 Author Share Posted March 16, 2012 awesome, perfect. thanks guys for your help. It worked like a charm Quote Link to comment https://forums.phpfreaks.com/topic/259059-join/#findComment-1328062 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.