Issue
I have tried this code but receiving error.
$queryfetch = 'select * from table';
$result = mysqli_query($connection, $queryfetch);
$row = mysqli_fetch_assoc($result);
$data = [];
foreach($row as $key) {
$data[] = [
'first_name' => $key['first_name'],
'last_name' => $key['last_name']
];
}
echo json_encode($data);
How can I json encode specific keys using php ?
Solution
I have solved..
$queryfetch = 'select * from table';
$result = mysqli_query($connection, $queryfetch);
$row = mysqli_fetch_assoc($result);
$data[] = array(
'first_name' => $row['first_name'],
'last_name' => $row['last_name']
);
echo json_encode($data);
This code is working very well..
Answered By - Dhaval Makwana Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.