SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem outputting multi-table SQL query array values

    Please can someone explain what I'm doing wrong here. My SQL query works fine, but when I try and output the array values in PHP nothing shows up. If I simplify the query it works like a charm, but the moment I start querying multiple tables it does not output anything:

    Code:
    <?php
    
    //Get data from mySQL
    
    $sql = "SELECT items.number AS number, items.model AS model, 
    items.serial AS serial, items.description AS description, 
    items.value AS value, equipment.prefix AS prefix, 
    manufacturers.manufacturer AS manufacturer, 
    conditions.conditions AS conditions, locations.location AS location,
    status.status AS status 
    FROM items, equipment, manufacturers, conditions, locations, status 
    WHERE items.prefix_id = equipment.equipment_id 
    AND items.manufacturer_id = manufacturers.manufacturer_id 
    AND items.condition_id = conditions.condition_id 
    AND items.location_id = locations.location_id 
    AND items.status_id = status.status_id;";
    
    $result = mysql_query($sql);
    
    while($row = mysql_fetch_assoc($result)){
    
    echo $row['number'] . $row['model'];
    echo "<br/>";
    
    }
    
    ?>
    Any suggestions would be appreciated. Thanks in advance.

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The fact that nothing is being output is a very strong indicator that your SQL query is not working fine. Do two things:
    Change
    PHP Code:
    $result mysql_query($sql); 
    to
    PHP Code:
    $result mysql_query($sql)
        or die(
    "Query failed: ".mysql_error()); 
    Then, just before your while loop,
    PHP Code:
    echo mysql_num_rows($sql); 
    Also make sure error reporting is turned on.
    PHP questions? RTFM
    MySQL questions? RTFM


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
  •