Reputation: 5
I am working on preparing a private message system
the problem is here and now that it will only show one even though there are 4 into the database.
I want it to display all 4 at once, not just one of them.
The problem can be seen here
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;
}
Upvotes: 0
Views: 258
Reputation: 41168
At the moment you read one line and then close the result.
You need to loop through the results reading and processing one line at a time and then only once you are done close the result.
Upvotes: 2