reece_1989 Posted July 28, 2009 Share Posted July 28, 2009 Hi, I have two tables in a db : individual and groups Individual: T1 -is a booking ref (auto increment) T2 -is a group ref Group: ID -is ID Number (auto increment) name -is a group name What id like to do is match T2 in individual with ID in groups to show 'name' on a php page. Any ideas in the right direction would help alot!! Im completely stuck My php code works in order to show everything from individual in tables in php: <?php $username="username"; $password="password"; $database="database"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM individual"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table width="100%" border="2" bordercolor="#000000" cellpadding="2" cellspacing="0" rules="rows" frame="hsides"> <tr> <th class="style1" align="left">Booking Ref</th> <th class="style1" align="left">Group ID</th> <th class="style1" align="left">Group name</th> </tr <? $i=0; while ($i < $num) { $T1=mysql_result($result,$i,"T1"); $T2=mysql_result($result,$i,"T2"); ?> <tr> <td class="style1" width="200"><? echo $T1; ?></td> <td class="style1" width="200"><? echo $T2; ?></td> </tr> <? $i++; } echo "</table>"; ?> Thanks !!!! Link to comment https://forums.phpfreaks.com/topic/167774-solved-display-multiple-records-from-2-tables/ Share on other sites More sharing options...
MadTechie Posted July 28, 2009 Share Posted July 28, 2009 1. please use code tags 2. read up on MySQL JOIN's $query="SELECT * FROM `individual` LEFT JOIN `Group` ON `individual`.T2 = `Group`.ID"; Link to comment https://forums.phpfreaks.com/topic/167774-solved-display-multiple-records-from-2-tables/#findComment-884792 Share on other sites More sharing options...
reece_1989 Posted July 29, 2009 Author Share Posted July 29, 2009 1. please use code tags 2. read up on MySQL JOIN's $query="SELECT * FROM `individual` LEFT JOIN `Group` ON `individual`.T2 = `Group`.ID"; Thank you so much!! Helped loads. Ill use code tags in future I didnt realise Link to comment https://forums.phpfreaks.com/topic/167774-solved-display-multiple-records-from-2-tables/#findComment-886201 Share on other sites More sharing options...
MadTechie Posted July 30, 2009 Share Posted July 30, 2009 I've clicked solved (bottom left) as i think this is solved but really you should be clicking it Link to comment https://forums.phpfreaks.com/topic/167774-solved-display-multiple-records-from-2-tables/#findComment-886815 Share on other sites More sharing options...
reece_1989 Posted July 30, 2009 Author Share Posted July 30, 2009 ahh thats where the button is. i was looking all over ! read the t+cs and help stuff-couldnt find anything about the solved button!! i cant work this forum, no wonder i cant code php!! Thanks! Link to comment https://forums.phpfreaks.com/topic/167774-solved-display-multiple-records-from-2-tables/#findComment-886919 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.