Encoding multiple rows from prepared statement in php
I am using msqli not PDO, and procedural php not OOP.


While you should. 

Because it will make the whole mess into three blimmin' lines

&lt;?php
require 'connect.php';

$statement = $con-&gt;prepare("SELECT * FROM `lecturers_general` WHERE ? IN (lecturer_id, title, first_name, middle_name, last_name, course1, course2, course3, course4, course5, course6, office_number, office_building, department)");
$statement-&gt;execute([$_REQUEST["query"]]);
echo json_encode(['lecturers: ' =&gt; $statement-&gt;fetchAll()]);