dongwen7380 2009-01-28 02:58
浏览 18

即使使用NULLS,也可以使用while()显示

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>
  • 写回答

1条回答 默认 最新

  • dounong5373 2009-01-28 03:31
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分