How to display json_encode via $wpdb

I’ve been struggling for quite a while how to make this work.

I created a custom php file, and used it as a template page. [below code]

Read More

I also ended up with this link //localhost/site/?page_id=43

If I want to query an id, I just need to add page_id=43&id=3 and it will display aa member name associated with the ID.

Whenever I query an ID, I only get {"result":[]} on that page.

Can someone check my code please?

/*
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));
    }

Related posts