Is it possible to get mysqli to spit out an array directly that I then json_encode with php (to retrieve with jquery) ?
I mean.. avoid making a while loop
I have this:
$sql = 'SELECT id, name FROM thetable';
$stmt = $conn->prepare($sql);
if ($stmt) {
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->bind_result($sql_id, $sql_name);
$json = array();
while($row = $stmt->fetch()){
$json[] = $sql_id.'=>'.$sql_name;
}
echo json_encode($json);
}
}
(this is just a simplyfied short version of my code)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…