我正在尝试将 mysqli 准备语句结果存储在数组中。所以我可以使用 json 编码方法并在其他页面中使用它。
目前它仅返回 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;
}
最佳答案
$data = array();
while ($result->fetch()){
$data[] = array(
"name" => $name,
"email" => $email,
"description" => $description,
"mobile" => $mobile,
"newDate" => date("d-M-Y", strtotime($post_date))
);
}
感谢弗雷德。这解决了问题。
关于php - 将mysql准备查询结果存储在数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36377195/