1

I have a table and I am displaying its contents using PHP and a while(); I have about three fields in the table that are NULL but can be change, but I want them to still display all the results in my table.

But, it only shows the records with data in EVERY field. Anyone how I can display it? I get a count of the table and it gives me 2, but only displays one.

<h3>Viewing All Updates</h3>
<h4>Below are all active updates for COTC</h4>
<table>
    <thead>
        <tr>
                <th>Site Name</th>
                <th>Page</th>
                <th>Flag</th>
                <th>Date Sent</th>
                <th>View</th>
        </tr>
    </thead>
    <tbody>
        <?php
    $sql    = "SELECT sname,page_name,date_submitted,u_id,clients.c_id,flag,completed FROM updates INNER JOIN clients ON updates.c_id = clients.c_id INNER JOIN pages ON updates.page = pages.p_id ORDER BY date_submitted DESC";
    $query  = mysql_query($sql) or die(mysql_error());
    while($row = mysql_fetch_array($query)){
        $completed = $row['completed'];
        if($completed == 1){
                print '<tr class="quiet">'; 
        }else{
                print '<tr>'; 
        }
                print '<td>'.$row['sname'].'</td>'; 
                print '<td>'.$row['page_name'].'</td>'; 
                print '<td>'.$row['flag'].'</td>';
                print '<td>'.$row['date_submitted'].'</td>';
                print '<td class="center"><a href="?c=displayupdate&id='.$row['u_id'].'" title="View update for '.$row['sname'].'" id="'.$row['u_id'].'"><img src="images/page_edit.png" alt="Edit entry!" /></a></td>';
        print '</tr>';
    }
?>
    </tbody>
</table>
4
  • The PHP in question would help immensely; it sounds like your condition is aborting early (first loop), but without the code in question... that is just a Wild Guess(tm). Commented Jan 28, 2009 at 3:01
  • That sounds unusual - could you include your while() in the question? Commented Jan 28, 2009 at 3:02
  • Looking at the code, it's not wrong. My guess is the SQL joins are not doing what you think they are doing. Commented Jan 28, 2009 at 3:30
  • Any suggestions on how to clean it up? I can explain any relationships to you. Commented Jan 28, 2009 at 13:38

1 Answer 1

1

Your PHP is correctly printing every row returned. I believe your problem is in the query.

SELECT sname,page_name,date_submitted,u_id,clients.c_id,flag,completed 
FROM updates INNER JOIN clients ON updates.c_id = clients.c_id 
             INNER JOIN pages ON updates.page = pages.p_id
ORDER BY date_submitted DESC

This query will only return a row in updates if it has a matching one in clients and a matching one in pages. If you want the clients or the pages joins to be optional (a updates row that has c_id or page of NULL will still return) change them from INNER JOINs to LEFT JOINs.

Sign up to request clarification or add additional context in comments.

3 Comments

It is going to be other fields that AREN't going to be displayed within my while(); but used else where.
... I'm not sure I'm following
All my rows in my table with ALL of their fields filled in with data show fine. If the anyone one of the fields has NULL as their value, they will not display using the code I posted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.