i having problem on exporting result of prepared statement using mysqli.
$age = "young"; $rows = array(); $mysqli = new mysqli($db_hostname, $db_username, $db_password, $db_database); $stmt = $mysqli->prepare("select fname, lname users age=?"); $stmt->bind_param('s', $age); $stmt->execute(); $stmt->bind_result($thefname,$thelname); while($stmt->fetch()) { array_push($rows, $thefname,$thelname); } $stmt->close(); $mysqli->close(); echo json_encode($rows); as can see trying echo out json_encode($rows); each of rows json array :
[ {"firstname":"john", "lastname":"doe"}, {"firstname":"anna", "lastname":"smith"}, {"firstname":"peter","lastname":"jones"} ] but getting is
["john", "doe", "anna", "smith", "peter", "jones"] can please let me know why happening , how can fix it
push proper array -
array_push($rows, array('firstname' => $thefname, 'lastname' => $thelname));
Comments
Post a Comment