Thundarfoot Posted January 31, 2008 Share Posted January 31, 2008 I am a noob working on my second script. I have 2 tables A & B Table A has 3 columns, the third column contains a number which represents the id of an entry in table B. I know how to query table a for its 3 columns and can show that output in a dynamic table. However this just shows the number in the thrid column.... I need to figure out how to take the number and fetch the correct entry from table b instead. Any help would be appreciated. Thank you for your time. Link to comment https://forums.phpfreaks.com/topic/88702-solved-join-2-tables-how/ Share on other sites More sharing options...
Cep Posted January 31, 2008 Share Posted January 31, 2008 You need a join in your sql statement, read this, http://en.wikipedia.org/wiki/Join_%28SQL%29 Link to comment https://forums.phpfreaks.com/topic/88702-solved-join-2-tables-how/#findComment-454226 Share on other sites More sharing options...
Thundarfoot Posted January 31, 2008 Author Share Posted January 31, 2008 thank you for that link, it helps explain things a lot. But I am still having trouble making it work. I belive the join code I need to use is.. SELECT * FROM cubes LEFT OUTER JOIN mobs ON drops_from.id = mobs.id Should I be placing this in a query? I have tried to add the abovet o a query command but to no avail. here is the code I am working with now... Thank you in advance for any help you can give. mysql_select_db($database_LWC, $LWC); $query_Rs1_cubes = "SELECT * FROM cubes"; $Rs1_cubes = mysql_query($query_Rs1_cubes, $LWC) or die(mysql_error()); $row_Rs1_cubes = mysql_fetch_assoc($Rs1_cubes); $totalRows_Rs1_cubes = mysql_num_rows($Rs1_cubes); mysql_select_db($database_LWC, $LWC); $query_Rs2_Mobs = "SELECT * FROM mobs"; $Rs2_Mobs = mysql_query($query_Rs2_Mobs, $LWC) or die(mysql_error()); $row_Rs2_Mobs = mysql_fetch_assoc($Rs2_Mobs); $totalRows_Rs2_Mobs = mysql_num_rows($Rs2_Mobs); ?> <html> <body> <table border="1"> <tr> <td>id</td> <td>Cube Type</td> <td>Drops From</td> </tr> <?php do { ?> <tr> <td><?php echo $row_Rs1_cubes['id']; ?></td> <td><?php echo $row_Rs1_cubes['Cube Type']; ?></td> <td><?php echo $row_Rs1_cubes['Drops From']; ?></td> </tr> <?php } while ($row_Rs1_cubes = mysql_fetch_assoc($Rs1_cubes)); ?> </table> <p> </p> </body> </html> <?php mysql_free_result($Rs1_cubes); mysql_free_result($Rs2_Mobs); ?> Link to comment https://forums.phpfreaks.com/topic/88702-solved-join-2-tables-how/#findComment-454721 Share on other sites More sharing options...
revraz Posted January 31, 2008 Share Posted January 31, 2008 SELECT * FROM cubes JOIN mobs ON (cubes.id = mobs.id) Depending on what the fieldname is in cubes that you want to link mobs with. Link to comment https://forums.phpfreaks.com/topic/88702-solved-join-2-tables-how/#findComment-454726 Share on other sites More sharing options...
Thundarfoot Posted January 31, 2008 Author Share Posted January 31, 2008 Thank you! Link to comment https://forums.phpfreaks.com/topic/88702-solved-join-2-tables-how/#findComment-454754 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.