如何在wordpress $ wpdb中使用mysqli_fetch_array

can someone help me convert this to wordpress friendly code.

basically, im creating a custom page where i want to dispaly json_encode arrays. based on the member ID input.

so if i append id=3 on my custom wordpress page. i want to display the associated name for that id.

when i run below code and type this on my browser http://localhost/site/?page_id=43&id=3 i only get this on my page {"result":[]}

this is my code. i just need to know how to make mysqli_fetch_array work in wordpress.

/*
Template Name: getID
*/

global $wpdb;
if (isset($_GET['id']) === true && empty($_GET['id']) === false) {      
    $query = $wpdb->get_results("SELECT * FROM `memberid` WHERE `memberid` = `$_GET['id']`");

   $array = array();

   while ($row = mysqli_fetch_array($query)) {
    array_push($array, array('name' => $row [2]);
   }

   echo json_encode(array("result" => $array));
}

i think i managed to figure this out. since i wanted to retrieve the numerical Array.

i need to add ARRAY_N on my query

$query = $wpdb->get_results("SELECT * FROM `table`, ARRAY_N );

and just found out, that while loop won't work. so i used foreach

foreach ($query as $row) {
        array_push($array, array('name' => $row[2]);
    }
echo json_encode(array("result" => $array));