Php 使用HTML表格标记并行显示两个数据库表格内容

Php 使用HTML表格标记并行显示两个数据库表格内容,php,html-table,Php,Html Table,我试图通过截短新通知的前20个字符并将其放入中来显示新通知的列表,因此如果用户想要阅读整个内容,可以单击hypered链接并继续阅读 有两种类型的通知(我正试图打印一个HTML表,第一列为一种通知类型,第二列为另一种类型),这两种类型是(每月评估反馈和一般考试反馈) 以下是我所做的: <?php $sql = "SELECT * FROM msgs WHERE stdID='".$id."' AND opened='0'"; $query = mysql_query($sql); $dat

我试图通过截短新通知的前20个字符并将其放入
中来显示新通知的列表,因此如果用户想要阅读整个内容,可以单击hypered链接并继续阅读

有两种类型的通知(我正试图打印一个HTML表,第一列为一种通知类型,第二列为另一种类型),这两种类型是(每月评估反馈和一般考试反馈)

以下是我所做的:

<?php
$sql = "SELECT * FROM msgs WHERE stdID='".$id."' AND opened='0'";
$query = mysql_query($sql);
$data = mysql_fetch_array($query);
$sql2 = "SELECT * FROM exam WHERE stdID='".$id."' AND evaluated='1'";
$query2 = mysql_query($sql2);
$data2 = mysql_fetch_array($query2);

if (mysql_num_rows($query) > 0 || mysql_num_rows($query2) > 0)
{   echo '<table border="1"><tr><th width="10%" align="right" style="margin-right:200%;"></th><th width="20%" align="right" style="padding-bottom:20px">Monthly Evaluation Feedback</th><th width="20%" align="right" style="padding-bottom:20px">General Exam Feedback</th></tr>';
            while ($row = mysql_fetch_row($query) || $row2 = mysql_fetch_row($query2))
    {
        if($row2 = mysql_fetch_row($query2))
        {   echo '<tr><td width="10%" align="right"></td>';
            echo '<td width="20%" align="right"><span class="toggle" style="padding:3px;"><a id="hline'.$row[0].'" style="cursor:pointer;" onClick="markAsRead('.$row[0].')"/>- '.stripslashes(substr($row[1],0,20)).'</a></span></td>';
            echo '<td width="20%" align="right"><span class="toggle" style="padding:3px;"><a id="hline'.$row2[0].'" style="cursor:pointer;" onClick="markAsRead('.$row2[0].')"/>- '.stripslashes(substr($row2[2],0,20)).'</a></span></td></tr>'; //This line wont print the truncated msg (substr($row2[2],0,20)).
        } else {
            echo '<tr><td width="10%" align="right"></td>';
            echo '<td width="20%" align="right"><span class="toggle" style="padding:3px;"><a id="hline'.$row[0].'" style="cursor:pointer;" onClick="markAsRead('.$row[0].')"/>- '.stripslashes(substr($row[1],0,20)).'</a></span></td></tr>'; //And this line wont print the truncated msg (substr($row[2],0,20)).
        }
    } echo '</table>';
}
else {echo 'there is no new notification';}
?>

它工作正常,但正如我在代码
stripslashes(substr($row[1],0,20))
中提到的,它不会显示反馈的前20辆车!
我这样做是为了避免
$row2
未定义,因为
$row
总是大于
$row2

旁注:2014年将在不到100小时内到来!不要再使用了,使用或者相反,和技术…谢谢你,我会做一些关于MySQLi和PDO的搜索。它没有发挥神奇的作用,同样的错误出现了,这就是为什么我说它是一个“旁注”。对于您的问题,1)
stripslashes
不是清理HTML输出的有效方法;2)
var\u dump($row)
var\u dump($row2)
查看发生了什么。我看到的一个引人注目的问题是,
$query2
$row
的双重获取可能是
false