I take it from the database and send it via ajax (wordpress). Everything works fine, except that I don't get the first row from the database. As I read on the Internet, a similar problem is in the array, maybe. Can someone explain and help me fix it so that all rows are displayed?
Code:
$sql = $wpdb->prepare( "SELECT * FROM users" );
$count = 0;
$user_object = array();
foreach( $wpdb->get_results( $sql ) as $key => $row ) {
$user_id = $row->user_ID;
$user_name = $row->user_name;
$user_object[$count]= array(
"user_ID"=>$user_id,
"user_name"=>$user_name,
);
$count++;
}
return wp_send_json( $user_object );