Posted in PHP, SQL

Create an array from a SQL query in PHP

// — Retrieve the list of questions ——————————————

$sql = “SELECT _QUESTION FROM questions WHERE _DEPT = ‘$dept'”; 

$db = new MysqliDb(‘CES’);

$selectStatus = $db->rawQuery($sql);

$questionArray = [];

if ($selectStatus > 0) {

$tmp[‘message’] = ‘Central evaluation system – Questions loaded successfully’;
$tmp[‘success’] = ‘Y’;

foreach ($selectStatus as $row) {

$questionArray[] = $row[‘_QUESTION’]; 

}

}