所以我的查询说有1条消息,但它没有显示在表格中
查询
<?php
//Unread
$req1 = $db->query('
SELECT
m1.id,
m1.title,
m1.timestamp,
m1.user1,
m1.user2,
m2.id as reps,
blog_users.username
FROM
pm as m1,
pm as m2,
blog_users
WHERE
((m1.user1="'.$session->username.'" and m1.user1read="no" and blog_users.username=m1.user2)
OR
(m1.user2="'.$session->username.'" and m1.user2read="no" and blog_users.username=m1.user1)) and m1.id2="1" and m2.id=m1.id
group by
m1.id
order by
m1.id desc');
$req1->execute();
$req1c = $req1->fetchAll();
$result = $req1->rowCount();
print_r($req1->errorInfo());
?>
errorinfo的结果
Array ( [0] => 00000 [1] => [2] => )
发布表
<?php
//We display the list of unread messages
while($dn1 = $req1->fetch())
{
?>
<tr>
<td class="left"><a href="read_pm.php?id=<?php echo $dn1['id']; ?>"><?php echo htmlentities($dn1['title'], ENT_QUOTES, 'UTF-8'); ?></a></td>
<td><?php echo $dn1['reps']-1; ?></td>
<td><a href="profile.php?id=<?php echo $dn1['userid']; ?>"><?php echo htmlentities($dn1['username'], ENT_QUOTES, 'UTF-8'); ?></a></td>
<td><?php echo date('Y/m/d H:i:s' ,$dn1['timestamp']); ?></td>
</tr>
<?php
}
?>
它应该显示1条消息,但它没有显示。还有一点很奇怪,它没有显示,因为mysql中有结果。
答案 0 :(得分:1)
我认为这种情况正在发生,因为fetchAll()正在将资源指针设置为结果集的末尾,所以当你到达while循环时,结果认为没有剩下的行可以获取。
我认为在结果对象上有一个rewind()方法,但你可能最好将fetchAll()的结果赋给一个数组,并在“posts table”脚本中迭代它。