mrhorror Posted July 22, 2008 Share Posted July 22, 2008 Hi I wan't to create a code that in a while loop list the content of table1 while looking for a matching result in table2. Table1 contains the main data Table2 contains keywords and description for the names in table1. example: Table1 ID - Title 1 - Intel core 2 2 - Intel Quad 3 - Amd 3200+ Table2 Titl - Description Intel - A Processor Amd - Another Processor This code below kinda shows what i wan't todo, but does obviously not work //list from table1 while(list($id, $title) = mysql_fetch_row($go->lists)) { $i++; echo $title; //list from table2 $query = "SELECT * FROM info where titl LIKE '%$title%'"; $result = mysql_query($query); if (mysql_num_rows($result)) { $row = mysql_fetch_array($result); echo $row['Description']; }else{ } } Hope you understand what i mean, i'm not so good at english Thanks Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 22, 2008 Share Posted July 22, 2008 You'd use a join. Quote Link to comment Share on other sites More sharing options...
mrhorror Posted July 22, 2008 Author Share Posted July 22, 2008 You'd use a join. Could you please give me a small sample code? Thanks i have tried this but that doesn't work $query = "SELECT table1.title, table2.titl ". "FROM table1, table2". "WHERE table2.titl = table1.title"; $result = mysql_query($query) or die(mysql_error()); // Print out the contents of each row into a table while($row = mysql_fetch_array($result)){ echo $row['title']. " - ". $row['Description']; echo "<br />"; } Quote Link to comment Share on other sites More sharing options...
fenway Posted July 23, 2008 Share Posted July 23, 2008 What doesn't work about it? 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.