ace2721 Posted February 18, 2011 Share Posted February 18, 2011 Hi Guys what I need to do is display data from two different tables that equal the same value in a specific field Table one has ID Title Course content table two has ID Title Start date End date I need a query that says if title from table one matches title from table 2 then will display the start and end date from table two sorry if this is really simple I am a newbie thanks inadvance Quote Link to comment https://forums.phpfreaks.com/topic/228112-help-with-displaying-content-from-two-fields-that-equal-the-same/ Share on other sites More sharing options...
denno020 Posted February 18, 2011 Share Posted February 18, 2011 I dont know exactly how to do it, but I know that you're going to want to look at Joins. You will join the two tables using the ID and title, and then you can easily echo out the dates.. Again, I don't know how to do this off the top of my head. I could easily do a Google search, find out and then tell you, but it will be much more beneficial to you if you Google it yourself . Denno Quote Link to comment https://forums.phpfreaks.com/topic/228112-help-with-displaying-content-from-two-fields-that-equal-the-same/#findComment-1176331 Share on other sites More sharing options...
eutu9 Posted February 18, 2011 Share Posted February 18, 2011 The mysql query should look like this: $r = mysql_query("SELECT * FROM table_one LEFT JOIN table_two ON table1_field = table2_field"); LEFT JOIN takes every record from `table one`, and attaches the records from `table two` for which the specified condition is true. Quote Link to comment https://forums.phpfreaks.com/topic/228112-help-with-displaying-content-from-two-fields-that-equal-the-same/#findComment-1176397 Share on other sites More sharing options...
ace2721 Posted February 21, 2011 Author Share Posted February 21, 2011 Hi Guys thanks so much for your help I will try it today and let you know how I get on, Thanks Quote Link to comment https://forums.phpfreaks.com/topic/228112-help-with-displaying-content-from-two-fields-that-equal-the-same/#findComment-1177493 Share on other sites More sharing options...
ace2721 Posted February 21, 2011 Author Share Posted February 21, 2011 Hi Guys I have run the query and this is what I am getting, mysql Column 'title' in on clause is ambiguous Quote Link to comment https://forums.phpfreaks.com/topic/228112-help-with-displaying-content-from-two-fields-that-equal-the-same/#findComment-1177495 Share on other sites More sharing options...
PHPNooblar Posted February 21, 2011 Share Posted February 21, 2011 ace, try read through this page: http://www.tizag.com/mysqlTutorial/mysqljoins.php Another member "harristweed" linked it to me in a thread I recently started and it solved my query. I think what you are trying to do is pretty much exactly what they cover in this tutorial, using Joins. *edit Actually, ignore that - I see this thread has already been marked as "Solved"! Quote Link to comment https://forums.phpfreaks.com/topic/228112-help-with-displaying-content-from-two-fields-that-equal-the-same/#findComment-1177539 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.