182x Posted July 19, 2007 Share Posted July 19, 2007 Hey guys, In order to display data from sql queries in a table I have had to create two different queries and then put the results into different arrays so this can be achieved as when I preform a join query it does not seem to work. I was just wondering can this be achieved with queries which make use of more than one table or are two different arrays the only way to go? thanks. example: while($s1=mysql_fetch_array($query1)) { $s2=mysql_fetch_array($query2); echo "<tr class='style4'><td>".$s1['ds']."</td><td>".$s2['hy']."</td></tr>"; } Quote Link to comment Share on other sites More sharing options...
trq Posted July 19, 2007 Share Posted July 19, 2007 I was just wondering can this be achieved with queries which make use of more than one table or are two different arrays the only way to go? A join is the way to go if the data can be related. Maybe post your query and well try and help get it working. Quote Link to comment Share on other sites More sharing options...
182x Posted July 19, 2007 Author Share Posted July 19, 2007 I think i got the join working but how is this data displayed in a table for example in the code below i don't think the array elements can be accessed like tableA.ds and tableB.hy while($s1=mysql_fetch_array($query1)) { $s2=mysql_fetch_array($query2); echo "<tr class='style4'><td>".$s1['ds']."</td><td>".$s2['hy']."</td></tr>"; } Quote Link to comment Share on other sites More sharing options...
trq Posted July 19, 2007 Share Posted July 19, 2007 The code you posted runs two queries.... post your attempt at a join. Quote Link to comment Share on other sites More sharing options...
182x Posted July 19, 2007 Author Share Posted July 19, 2007 Here it is. $test=select * from tableA, tableB where tableAId = tableBId; $query=mysql_query($test, $link_id) or die(mysql_error()); while($get=mysql_fetch_array($query)) { echo "<tr class='style4'><td>".$query['tableA.ds']."</td><td>".$query['tableB.hy']."</td></tr>"; } 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.