CODE!
<?php
$stmt = $DB_con->prepare('SELECT userID, FullName, BirthDate, DeathDate FROM name');
$stmt->execute();
if($stmt->rowCount() > 0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
echo "<td align='center'><div class='listxtNB' style='width:30px;'>" .$row['userID']. "</div></td>";
echo "<td align='center'><div class='listxtNB' style='width:135px;'>" .$row['FullName']. "</div></td>";
echo "<td align='center'><div class='listxtNB' style='width:95px;'>" .$row['BirthDate']. "</div></td>";
echo "<td align='center'><div class='listxtNB' style='width:95px;'>" .$row['DeathDate']. "</div></td>";
echo "<td align='center'><div class='listxtNB' style='width:45px;'><a href='editform.php?edit_id=".$row['userID']."'>EDIT</a></div></td>";
echo "<td align='center'><div class='listxtNB' style='width:45px;'><a href='?delete_id=".$row['userID']."' onclick='return confirm('sure to delete ?')>DELETE</a></div></td>";
echo "</tr></table>";
?>
答案 0 :(得分:0)
您必须稍微调整以下代码:
<?php
$stmt = $DB_con->prepare('SELECT userID, FullName, BirthDate, DeathDate FROM name');
$stmt->execute();
if($stmt->rowCount() > 0) {
echo "<table>";
while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
extract($row);
echo "<tr>";
echo "<td align='center'><div class='listxtNB' style='width:30px;'>" .$row['userID']. "</div></td>";
echo "<td align='center'><div class='listxtNB' style='width:135px;'>" .$row['FullName']. "</div></td>";
echo "<td align='center'><div class='listxtNB' style='width:95px;'>" .$row['BirthDate']. "</div></td>";
echo "<td align='center'><div class='listxtNB' style='width:95px;'>" .$row['DeathDate']. "</div></td>";
echo "<td align='center'><div class='listxtNB' style='width:45px;'><a href='editform.php?edit_id=".$row['userID']."'>EDIT</a></div></td>";
echo "<td align='center'><div class='listxtNB' style='width:45px;'><a href='?delete_id=".$row['userID']."' onclick='return confirm('sure to delete ?')>DELETE</a></div></td>";
echo "</tr>";
}
echo "</table>";
}
?>
答案 1 :(得分:0)
我想这应该可行:
<?php
$stmt = $DB_con->prepare('SELECT userID, FullName, BirthDate, DeathDate FROM name');
$stmt->execute();
if($stmt->rowCount() > 0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
echo "<tr>";
echo "<td align='center'><div class='listxtNB' style='width:30px;'>" .$row['userID']. "</div></td>";
echo "<td align='center'><div class='listxtNB' style='width:135px;'>" .$row['FullName']. "</div></td>";
echo "<td align='center'><div class='listxtNB' style='width:95px;'>" .$row['BirthDate']. "</div></td>";
echo "<td align='center'><div class='listxtNB' style='width:95px;'>" .$row['DeathDate']. "</div></td>";
echo "<td align='center'><div class='listxtNB' style='width:45px;'><a href='editform.php?edit_id=".$row['userID']."'>EDIT</a></div></td>";
echo "<td align='center'><div class='listxtNB' style='width:45px;'><a href='?delete_id=".$row['userID']."' onclick='return confirm('sure to delete ?')>DELETE</a></div></td>";
echo "</tr>";
}
?>
答案 2 :(得分:0)
表格标签在LOOP中关闭,你不需要很多回声
<?php
$stmt = $DB_con->prepare('SELECT userID, FullName, BirthDate, DeathDate FROM name');
$stmt->execute();
if($stmt->rowCount() > 0)
{
echo "<table>";
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
echo "<tr><td align='center'><div class='listxtNB' style='width:30px;'>" .$row['userID']. "</div></td>
<td align='center'><div class='listxtNB' style='width:135px;'>" .$row['FullName']. "</div></td>
<td align='center'><div class='listxtNB' style='width:95px;'>" .$row['BirthDate']. "</div></td>
<td align='center'><div class='listxtNB' style='width:95px;'>" .$row['DeathDate']. "</div></td>
<td align='center'><div class='listxtNB' style='width:45px;'><a href='editform.php?edit_id=".$row['userID']."'>EDIT</a></div></td>
<td align='center'><div class='listxtNB' style='width:45px;'><a href='?delete_id=".$row['userID']."' onclick='return confirm('sure to delete ?')>DELETE</a></div></td>
</tr>";
}
echo "</table>";
}
?>