patrickm Posted April 16, 2007 Share Posted April 16, 2007 I'm having problems cracking a SQL/PHP nut. Situation: table 1 contains several information about products (among the field, there are $code and $product_description). T ???able 2 contains specific information with which can be determined which product you need (it also contains the field $code). From table (no.2) I select the right products when a certain variable = "something". The outcome is processed using while ($dump_resultaat = mysql_fetch_object($resultaat)) { ... } But here it comes ... in this loop, the valid info from field $code in $dump_resultaat should be used to retrieve information from table 1 in which there is also a field called $code. $code is used as a reference in both tables. How do I build this? I've tried to combine things in PHP, but unfortunately to no avail. Any pointers would be appriciated! Quote Link to comment https://forums.phpfreaks.com/topic/47247-solved-combine-data-from-two-tables-in-a-while-loop/ Share on other sites More sharing options...
jworisek Posted April 16, 2007 Share Posted April 16, 2007 can't get it all in one SQL statement? SELECT * FROM table1 LEFT JOIN table2 ON (table1.code=table2.code) where ..... Quote Link to comment https://forums.phpfreaks.com/topic/47247-solved-combine-data-from-two-tables-in-a-while-loop/#findComment-230504 Share on other sites More sharing options...
bubblegum.anarchy Posted April 17, 2007 Share Posted April 17, 2007 Use an inner join to return only all record in table 2 that have a matching table 1 id. Quote Link to comment https://forums.phpfreaks.com/topic/47247-solved-combine-data-from-two-tables-in-a-while-loop/#findComment-230869 Share on other sites More sharing options...
patrickm Posted April 18, 2007 Author Share Posted April 18, 2007 Thanks for the suggestions. I've done some searching and found a useful page on Wikipedia. Super! Quote Link to comment https://forums.phpfreaks.com/topic/47247-solved-combine-data-from-two-tables-in-a-while-loop/#findComment-231939 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.