slack Posted April 3, 2006 Share Posted April 3, 2006 Hi all,I have problem with displaying data from two tables. There are two tables as follows:TABLE1ID-------NAME1--------John2--------Mark3--------KellyTABLE2ID-------REF------REFNAME1--------A1--------Mark2--------A2--------Kelly3--------A3--------Kelly4--------A4--------MarkAs you can see REFNAME in TABLE2 referances NAME in TABLE1.In php I want the information to be displayed like this:JohnNONEMarkA1A4KellyA2A3I am not sure if this can be done by a SQL JOIN or some sort of loop.Can someone help me display the information I want.ThanksSlack Quote Link to comment Share on other sites More sharing options...
slack Posted April 4, 2006 Author Share Posted April 4, 2006 Problem solved.Had to use 2 loops. Code looks something like this:[code]$query = "SELECT * FROM TABLE1";$result = @mysql_query ($query);while($row = @mysql_fetch_array($result)){echo $row["NAME"];echo '<br>';$Name = $row["NAME"];$query2 = "SELECT * FROM TABLE2 WHERE TABLE2.REFNAME='$Name';$result2 = @mysql_query ($query2);while($row2 = @mysql_fetch_array($result2)){echo $row2["REFNAME"];}echo '<p> </p>';}[/code]Slack 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.