Php 查询正在计数中给出结果,但未显示在表中
因此,我的查询显示有1条消息,但它没有显示在表中 查询Php 查询正在计数中给出结果,但未显示在表中,php,pdo,Php,Pdo,因此,我的查询显示有1条消息,但它没有显示在表中 查询 <?php //Unread $req1 = $db->query(' SELECT m1.id, m1.title, m1.timestamp, m1.user1,
<?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());
?>
过账表
<?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中有一个结果。我认为这是因为fetchAll()正在将资源指针设置为结果集的结尾,所以当您进入while循环时,结果认为没有行可以提取
我认为result对象上有一个rewind()方法,但是您最好将fetchAll()的结果赋给一个数组,并在“posting table”脚本中对其进行迭代 这一行是什么用于?@YourCommonSense
未读邮件():
您在$result
中没有此计数吗?@YourCommonSense在“您没有未读邮件”部分中使用了1。但是因为我没有在页面中看到这条消息,所以问题中不需要pm。如果你不需要fetchAll()部分,那么为什么它会出现在代码中呢?可能就是把它扔掉?
<?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
}
?>