dimanche 29 mars 2015

how to check in database for records

i am using a simple database for a guestbook. I just can't figure out how to check if there has nobody written in the guestbook yet. Because in that case, there should be an echo: "Be the first to write in the guestbook". Otherwise, the rows should be echoed. How can i do that?


Piece of the code:



if (mysqli_connect_errno($con))
{
echo "Connectie Database mislukt: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT name,message,email,datetime FROM guestbook");

while($row = mysqli_fetch_array($result))
{ ?>

<div class="velden"> <!-- voor styling van alle echo's; zie CSS -->
<div class="header">
<div class="naam"><?php echo $row['name']; ?></div> <!-- echo naam-->
<div class="email"><?php echo $row['email']; ?></div> <!-- echo email-->
<div class="tijd"><?php echo $row['datetime']; ?></div> <!-- echo datum en tijd-->

</div>

<div class="bericht"><?php echo $row['message']; ?></div> <!-- echo bericht-->

</div>
<?php } ?>


So there should be something like:



If(nobody has written) {
echo 'Be the first to write in the database";
} else {
//do the echo's
}

Aucun commentaire:

Enregistrer un commentaire