$sql= "SELECT team_name AS label, user_id as value
FROM d_getreal_captains ORDER BY team_name ASC";
$result = $bfit_connect->query($sql);
$rows = mysqli_fetch_assoc($result);
while( $rows = mysqli_fetch_assoc( $result ) ) {
$json[] = $rows;
}
此代码按预期工作,但它不返回表中的第一条记录(即第一个team_name和user_id)。我已经看到其他人已经建议使用mysql_data_seek重置行索引的修复程序,但我也知道这是不推荐的,并希望我的修复程序使用当前方法。感谢您的想法或建议......谢谢。
答案 0 :(得分:0)
$sql= "SELECT team_name AS label, user_id as value
FROM d_getreal_captains ORDER BY team_name ASC";
$result = $bfit_connect->query($sql);
//Here you used to take the first row out with mysqli_fetch_assoc, I removed this line
while( $rows = mysqli_fetch_assoc( $result ) ) {
$json[] = $rows;
}
答案 1 :(得分:0)
你在循环之外调用mysqli_fetch_assoc()
,这会从结果集中弹出第一个结果。您没有在任何地方使用这些值,因此您可以安全地删除它。
$result = $bfit_connect->query($sql);
$rows = mysqli_fetch_assoc($result); // <-- remove this