SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Threaded View

  1. #1
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    the Netherlands
    0 Post(s)
    0 Thread(s)

    ORDER BY statement???

    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:
    PHP Code:
        $sidCheck    mysql_query("SELECT * FROM relatie WHERE sid = 1");
    mysql_num_rows($sidCheck) > 0) {
          while (
    $rows    mysql_fetch_array($sidCheck)){
    $relatienawsql     mysql_query("SELECT * FROM relatienaw WHERE rid = $rid ");
    mysql_num_rows($relatienawsql) > 0){
    $row mysql_fetch_array($relatienawsql)){
    $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');          
                    <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 { 
    "no data found<br><br>";
    Please advise...
    How do I ORDER BY information that is not in the first SQL-statement Table?

    Last edited by jazztie; Aug 22, 2001 at 09:09.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts