【发布时间】:2014-01-02 18:57:30
【问题描述】:
我正在准备私信系统
问题就在这里,现在它只会显示一个,即使数据库中有 4 个。
我希望它同时显示所有 4 个,而不仅仅是其中一个。
问题可以看这里
http://billedeupload.dk/?v=rXFTj.png
$sql = "SELECT id, title, datoTime, checkpm FROM pm WHERE til=? ORDER BY datoTime DESC";
if ($stmt = $this->mysqli->prepare($sql))
{
$stmt->bind_param('i', $til);
$til = $_GET["id"];
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id, $title, $datoTime, $checkpm);
$stmt->fetch();
$count = $stmt->num_rows;
$stmt->close();
if($count >= 1)
{
?>
<tr>
<td><img src="/img/besked/reply.png" alt="svar" id="beskedu"></td>
<td><a href="/pm-set/<?php echo $id;?>/"><?php echo $title;?></a></td>
<td>
<?php
if($checkpm == 0)
{
?>
<a href="/pm-set/<?php echo $id;?>/"><img src="/img/besked/ulase.png" alt="ulæst" id="beskedu"></a>
<?php
}
else
{
?>
<a href="/pm-set/<?php echo $id;?>/"><img src="/img/besked/lase.png" alt="læst" id="beskedu"></a>
<?php
}
?>
</td>
<td><?php echo date("H:i - d, M - Y", strtotime($datoTime));?></td>
<td>Slet</td>
</tr>
<?php
}
else
{
?>
<div id="error"><p>Ingen besked</p></div>
<?php
}
}
else
{
echo 'Der opstod en fejl i erklæringen: ' . $this->mysqli->error;
}
【问题讨论】:
-
您使用 fetch 而不是 fetchAll ,您似乎也没有遍历结果
-
所以我必须做一个循环才能让它工作?
-
是的,否则你只是返回最后一个结果。也使用 $result->fetch_assoc() 代替 fetch。看这里*.com/questions/7239391/…
-
@LiamSorsby 我试过了,现在它对我有用:(
-
更新您的代码以便我们查看?