dimanche 4 février 2018

MySQLi result to array

So currently my code outputs 1 array, it doesn't display all. I understand that I need a while or foreach loop to display the rest.

Here is my current code:

    /**
 * Get work orders via email and password and institution id
 */
public function getWorkOrdersByInstitution($email, $password, $institution_id) {

    $work_order_stmt = $this->conn->prepare("SELECT * FROM project WHERE institution_id = ?");

    $work_order_stmt->bind_param("s", $institution_id);

    if ($work_order_stmt->execute()) {
        $workorder = $work_order_stmt->get_result()->fetch_assoc();
        $work_order_stmt->close();

       return $workorder;

    } else {
        return NULL;
    }
}

I want it to return the array. Currently this is what is returned (note: i am using json_encode when displaying the array):

{"project_id":1,"date":"Undefined","project_code":"ea60f6190c","title":"test","description":"test","demo_url":null,"project_category_id":null,"client_id":null,"company_id":null,"staffs":"4,5,","budget":0,"timer_status":0,"timer_starting_timestamp":null,"total_time_spent":0,"progress_status":null,"timestamp_start":"1516874400","timestamp_end":"1516878000","project_status":1,"project_note":null,"institution_id":12,"project_state":2,"strata_manager":6,"site_contact":7,"place_of_service":18}

So ultimately, I want all the rows to be stored in 1 array which I can return and use on another page.

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire