Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
Accounts
Articles / Notes
Biology
Chemistry
Computer Class
Daily Current Affairs
English
General Knowledge
History
Indian Law
Interview Questions
Mathematics
Muft Shiksha - Free Education
Science

JSON encode MySQL results

0
Akbar Khan

$sth = mysqli_query($conn, “SELECT …”);
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
————————————————–

$result = mysqli_query($conn, “SELECT …”);
$rows = mysqli_fetch_all($result); // list arrays with values only in rows
// or
$rows = mysqli_fetch_all($result, MYSQLI_ASSOC); // assoc arrays in rows

print json_encode($rows);

Add a Comment
Join for Teach