我想在数组中存储mysqli准备语句结果。所以我可以使用json编码方法并在其他页面中使用它。存储mysql准备在数组中的查询结果
此刻它只返回1行。我检查了查询和查询工作正常。
看来我正在做一些愚蠢的错误,但无法弄清楚。
$start = 2;
$limit = 2;
$result = $mysqli->prepare("SELECT name, email, description, mobile, post_date FROM users order by id DESC limit ?,?");
$result ->bind_param("ii", $start, $limit);
$result->execute();
$result->store_result();
$data = array();
$total = $result->num_rows;
if($result->num_rows > 0){
$result->bind_result($name, $email, $description, $mobile, $post_date);
while ($result->fetch()){
$data['name'] = $name;
$data['email'] = $email;
$data['description'] = $description;
$data['mobile'] = $mobile;
$post_date = $post_date;
$data['newDate'] = date("d-M-Y", strtotime($post_date));
//echo $name;
}
为什么不只是做你的查询并将结果推送到数组? – cpugourou
您在每次迭代时覆盖。 '$ data ['name']'只有最后一个名字,所有其他索引也是如此。 – chris85
@ chris85请解释。我没有找到你 – Ironic