gpt4 book ai didi

php - PHP 使用限制、与 SQL 的偏移量进行选择时出错

转载 作者:行者123 更新时间:2023-11-29 06:36:06 25 4
gpt4 key购买 nike

我正在尝试从数据库中选择数据。 php 脚本是从数据库表中从第一行开始选择 4 行,但代码最终只选择从第二行而不是第一行开始的 3 行。我应该怎么办?

<?php 

try{

require 'mysqli_connect.php';

$maxrow = 4;
$start = 0;

$query = "SELECT user_id , first_name , last_name, email , registration_date FROM users LIMIT ? , ?";
$stmt = mysqli_stmt_init($dbcon);
mysqli_stmt_prepare($stmt , $query);
mysqli_stmt_bind_param($stmt , 'ii' , $start ,$maxrow); // still showing only three rows and does not count from zero
mysqli_stmt_execute($stmt);
$record = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_array($record , MYSQLI_NUM);

if($record){

echo "<table>";
echo "<tr>";
echo "<th>user_id</th>";
echo "<th>first_name</th>";
echo "<th>last_name</th>";
echo "<th>email</th>";
echo "<th>registration_date</th>";
echo "</tr>";

while ($row = mysqli_fetch_array($record , MYSQLI_NUM)) {

$user_id = $row[0];
$first_name = $row[1];
$last_name = $row[2];
$email = $row[3];
$registration_date = $row[4];

echo '<tr>
<td><a href="edit_user.php?id=' . $user_id . '">Edit</a></td>
<td><a href="delete_user.php?id=' . $user_id . '">Delete</a></td>
<td>' . $last_name . '</td>
<td>' . $first_name . '</td>
<td>' . $email . '</td>
<td>' . $registration_date . '</td>
</tr>';
}
echo "</table>";
mysqli_free_result ($record); // Free up the resources.

}

}catch(Exception $e){
//echo $e->getMessage();
}catch(Error $e){
//echo $e->getMessage();
}

?>

最佳答案

此处选择第一行$row = mysqli_fetch_array($record , MYSQLI_NUM);。因此 while 中的 mysqli_fetch_array() 从第二行开始。

关于php - PHP 使用限制、与 SQL 的偏移量进行选择时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53792544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com