PHP/MySQL Order by column in a different table -
i running sql code:
sql=" select * channel_did "; $rs=mysql_query($sql,$pbx01_conn) or die(mysql_error()); $counter=0; $display=''; while($result=mysql_fetch_array($rs)) { $sql2="select * client id = '".$result["client_id"]."' "; $rs2=mysql_query($sql2,$pbx01_conn) or die(mysql_error()); $result2=mysql_fetch_array($rs2); }
so in channel_did
table client_id
column number lookup in client
table id equals channel_id.client_id
how can list (from channel_did)
order company
column in client
table?
**channel_id** id did client_id **client** id name company client.id = channel_did.client_id
write query inner join
both tables, select fields first table, , use column of second table sort rows
select a.* channel_did inner join client b on a.client_id = b.id order b.company
of course in case have 1 , 1 row in client
corresponding each row of channel_did
hope helps.
Comments
Post a Comment