I have a problem with an ORDER BY statement.
I have several tables in a Database
1. Relatie, which holds 'foreign key' information from several tables:
(relatie = relationship / customer)
sid = status ID
rid = RelatieNAW ID
nid = Netwerk ID (netwerk = network)
et cetera
2. RelatieNAW, which holds Name, Address, Companyname information
A customer (=company) can have 4 instances of a status. Status is held in a foreign key in table Relatie (see above).
I want to show a page with the customers which have the status (for instance) equals '1'. So, I wrote a SQL-statement which does this... but I want to ORDER BY 'Companyname', 'Address' or 'Name'.
And here is the problem. How do I ORDER BY in the first SQL-statement, while the first SQL-statement looks in a Table different from the one that holds the Information I want to ORDER BY?
I have used the following code:
Please advise...PHP Code:$sidCheck = mysql_query("SELECT * FROM relatie WHERE sid = 1");
if(mysql_num_rows($sidCheck) > 0) {
while ($rows = mysql_fetch_array($sidCheck)){
extract($rows);
$relatienawsql = mysql_query("SELECT * FROM relatienaw WHERE rid = $rid ");
if(mysql_num_rows($relatienawsql) > 0){
while($row = mysql_fetch_array($relatienawsql)){
extract($row);
$checkRelatie = mysql_query ("SELECT * FROM relatie WHERE rid = $rid");
if (mysql_num_rows($checkRelatie) > 0){
$nid = mysql_result($checkRelatie,0,'nid');
if ($nid != ''){
$checkNetwerk = mysql_query ("SELECT * FROM netwerk WHERE nid = $nid");
$netwerk = mysql_result($checkNetwerk,0,'n_naam');
}
}
print "
<tr bgcolor='#FBFBFB'>
<td valign='top' nowrap><b><a href='javascript:detailLid($rid);'> $Companyname</a></b></td>
<td valign='top' nowrap> $p_plaats </td>
<td valign='top' nowrap> $Name </td>
<td valign='top' nowrap> $netwerk </td></tr>
";
}
}
else {
print "no data found<br><br>";
}
}
}
How do I ORDER BY information that is not in the first SQL-statement Table?
Jazz




Bookmarks