所有錶行我做了一個HTML表,我能夠從MySQL表中檢索數據。但是,我只能顯示最後一個註冊表。我想展示給大家。顯示在<table>
我的代碼:
<?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>
正如你所看到的,現在我只是想一行。到目前爲止,我正在顯示最後一個註冊表。我想向他們展示一切,我該怎麼做?
你在表中有多個記錄呢? –
您需要在循環中發出錶行。 –
使用',而不是'mysql_' – lolbas