Posted in EasyUI, HTML, PHP, SQL

PHP – unserialise and JSON data for EasyUI

After034_E

require_once($_SERVER[‘DOCUMENT_ROOT’].’/xyz/db/MysqliDb.php’);

// — Parameters input ——————————————————–

$dept = (isset($_REQUEST[‘DEPT’])) ? $_REQUEST[‘DEPT’] : ”;
$template = (isset($_REQUEST[‘TEMPLATE’])) ? $_REQUEST[‘TEMPLATE’] : ”;

// — Define containers ——————————————————-

$terugvoer = array();
$tmp = array();

// — Retrieve the present list of questions ———————————-

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

$db = new MysqliDb(‘CES’);

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

if ($selectStatus > 0) {

foreach ($selectStatus as $row) {

$questionArray[] = $row[‘_QUESTION’];
$ynArray[] = $row[‘_YN’];
$commentonlyArray[] = $row[‘_COMMENTONLY’];

}

}

// — Retrieve the list of categories —————————————–

$sql = “SELECT _CATEGORY, _SUBCATEGORY FROM categories WHERE _DEPT = ‘$dept'”;

$db = new MysqliDb(‘CES’);

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

if ($selectStatus > 0) {

foreach ($selectStatus as $row) {

$categoryArray[] = $row[‘_CATEGORY’];
$subcategoryArray[] = $row[‘_SUBCATEGORY’];

}

}

// — Retrieve the TEMPLATE selection data ————————————

$sql = “SELECT _TEMPLATE, _UPTO30CAT, _UPTO30CATW FROM templates WHERE _TEMPLATE = ‘$template'”;

$db = new MysqliDb(‘CES’);

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

if ($selectStatus > 0) {

foreach ($selectStatus as $row) { // Only one row ….. [0]

$tmp[‘_TEMPLATE’] = $row[‘_TEMPLATE’];
$tmp[‘_UPTO30CAT’] = unserialize($row[‘_UPTO30CAT’]);
$tmp[‘_UPTO30CATW’] = unserialize($row[‘_UPTO30CATW’]);

foreach ($tmp[‘_UPTO30CAT’] as $key=>$value) {

if ($value != ”) {

$tmp[‘_CATEGORY’] = $categoryArray[$value];
$tmp[‘_SUBCATEGORY’] = $subcategoryArray[$value];

$tmp[‘_CWEIGHT’] = $tmp[‘_UPTO30CATW’][$key];

$searchVal = $tmp[‘_CATEGORY’];

$sql = “SELECT _CATEGORY, _SUBCATEGORY, _UPTO15QSUBHEADING, _UPTO15QUES, _UPTO15PUNT, _UPTO15WEIGHTS FROM categories WHERE _CATEGORY = ‘$searchVal'”;

$db = new MysqliDb(‘CES’);

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

if ($selectStatus > 0) {

foreach ($selectStatus as $row) {

// — Store questions as HTML representation ——————–

foreach (unserialize($row[‘_UPTO15QUES’]) as $key=>$value) {

if ($value != ”) {

$tmp[‘myHeadingsArray’] = unserialize($row[‘_UPTO15QSUBHEADING’]);

$tmp[‘_QSUBHEADING’] = $tmp[‘myHeadingsArray’][$key];

$tmp[‘myPointsArray’] = unserialize($row[‘_UPTO15PUNT’]);

$tmp[‘_QWEIGHT’] = $tmp[‘myPointsArray’][$key];

$tmp[‘_QUESTION’] = $questionArray[$value];

$terugvoer[] = $tmp;

// ————————————
$tmp[‘_CATEGORY’] = ”;
$tmp[‘_SUBCATEGORY’] = ”;
$tmp[‘_CWEIGHT’] = ”;
// ————————————

} // End if

} // End store questions as HTML representation

} // End while

} // End of Question code

}

}

}

}

echo json_encode($terugvoer);

?>