SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help joining a new table to a left join?

    Can somebody tell me how to add another JOIN to the SELECT statement below so it will select the "NAME" from the table "CATEGORY" then assign it the name c_name?

    PHP Code:
    $result mysql_query('SELECT customer.id, customer.usrname, menu.company FROM customer LEFT JOIN menu ON menu.customer_id = customer.id') or die ("Invalid query : Error 6.9");
     
    $listing '';
     while (
    $row mysql_fetch_assoc($result)) {
         if (
    $current_category != $row['c_name']) {
             
    $current_category $row['c_name'];
             
    $head "\n  <tr>\n";
             
    $head .= '    <td align="center" colspan="2">&nbsp;</td>'."\n";
             
    $head .= '  </tr>'."\n";
             
    $head .= '  <tr>'."\n";
             
    $head .= '    <th align="center" colspan="2">' $current_category '</th>'."\n";
             
    $head .= '  </tr>'."\n";
         } else {
             
    $head '';
         }
     
         
    $usrname $row['usrname'];
         
    $company $row['company'];
     
         
    $listing .= '  <tr>';
         
    $listing .= '    <td><a href="index.php?mid=' $usrname '">' stripslashes($company) . '</a></td>';
         
    $listing .= '  </tr>';
     } 
    Any help would be greatly appreciated.
    John Saunders

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Code:
    select customer.id
         , customer.usrname
         , menu.company 
         , category.name   as c_name
      from customer 
    left outer
      join menu 
        on menu.customer_id = customer.id
    left outer  
      join category
        on something.something = category.something
    you'll have to fill in the "somethings" yourself
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help! Do you know of a site that has a good tutorial on MySQL joins? I've read the MySQL manual but it's really hard to follow. If you know of a site that shows photographic diagrams of what each syntax does such as left outer join, right inner join, natural, etc.
    John Saunders

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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