I made a html table and I am able to retrieve data from the mysql table. However, I'm able to show the last registry only. I'd like to show them all.
My code:
<?php
$con = mysql_connect("localhost","x","x");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("x", $con);
$query = "SELECT * FROM noticias";
$comments = mysql_query($query);
while($row = mysql_fetch_array($comments, MYSQL_ASSOC))
{
$name = $row['nome'];
$email = $row['email'];
$website = $row['lugar'];
$comment = $row['comment'];
$timestamp = $row['data'];
$name = htmlspecialchars($row['nome'],ENT_QUOTES);
$email = htmlspecialchars($row['email'],ENT_QUOTES);
$website = htmlspecialchars($row['lugar'],ENT_QUOTES);
$comment = htmlspecialchars($row['comment'],ENT_QUOTES);
}
mysql_close($con); ?>
<table class="heavyTable">
<thead>
<tr>
<th>Nome</th>
<th>E-mail</th>
<th>Lugar</th>
<th>Notícia</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $name ?></td>
<td>$email</td>
<td>$website</td>
<td>$comment</td>
<td>$timestamp</td>
</tr>
</tbody>
</table>
As you can see, for now I'm trying one row only. So far, I'm getting the last registry shown. I want to show them all, how can I do it?
<?php
$con = mysql_connect("localhost","x","x");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("x", $con);
$query = "SELECT * FROM noticias";
$comments = mysql_query($query);
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysqli_fetch_array($comments))
{
echo "<tr>";
echo "<td>" . $row['nome'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Do something like this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With