【发布时间】:2016-08-18 20:22:49
【问题描述】:
我正在尝试从数据库中选择具有最高 ID 的一行并将其回显到表中的页面。
我可以手动运行查询,它可以正常工作,但是当我尝试通过 PHP 动态执行时;这没用。我的代码有什么问题?
<?php
$sql_query = "SELECT * FROM single_user_orders ORDER BY order_id DESC LIMIT 1";
$result = mysqli_query($dbconfig, $sql_query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
echo '<div class="row" style="margin-top: 30px;">';
echo '<div class="col-md-12">';
echo '<table class="table">';
if($count > 1) {
echo '<tr>';
echo '<th>Order ID</th>';
echo '<th>Status</th> ';
echo '<th>Order Total</th>';
echo '<th>Order Description</th>';
echo '</tr>';
while ($row = mysqli_fetch_array($result)) {
echo '<tr>';
echo '<td>'. $row['order_id'] .'</td>';
echo '<td>'. $row['status'] .'</td> ';
echo '<td>'. $row['order_total'] .'</td>';
echo '<td>'. $row['order_description'] .'</td>';
echo '</tr>';
}
}
echo '</table>';
echo '</div>';
echo '</div>';
?>
【问题讨论】:
-
你能描述一下
it does not work吗? -
没有错误显示?
-
没有错误,只是没有表格。
-
$count 的值是多少?
-
$count 的值为 1。