
<?php require_once('../Connections/hadithbd.php'); ?>
<?php require_once('../webassist/mysqli/rsobj.php'); ?>
<?php
$hadithBooksList = new WA_MySQLi_RS("hadithBooksList",$hadithbd,0);
$hadithBooksList->setQuery("SELECT hadithbook.BookID, hadithbook.totalHadith, hadithbook.BookNameBD, Count(hadithsection.BookID) AS totalSection FROM hadithbook LEFT OUTER JOIN hadithsection ON hadithbook.BookID = hadithsection.BookID WHERE hadithbook.Active = 1 GROUP BY hadithsection.BookID ORDER BY hadithbook.priority ASC");
$hadithBooksList->execute();
?>
<?php
while (!$hadithBooksList->atEnd()) {
?>
<?php
$sectionList = new WA_MySQLi_RS("sectionList",$hadithbd,0);
$sectionList->setQuery("SELECT hadithsection.SectionBD FROM hadithsection WHERE hadithsection.BookID = ?");
$sectionList->bindParam("i", "".($hadithBooksList->getColumnVal("BookID")) ."", "-1"); //WAQB_Param1
$sectionList->execute();
?>
<?php
$hadithBooksList->Results[$hadithBooksList->Index]["Sections"] = $sectionList->Results;
$hadithBooksList->moveNext();
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Generate Hadith Books JSON File</title>
</head>
<body>
<?php
header("Content-Type: application/json; charset=UTF-8");
die(json_encode($hadithBooksList->Results, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
?>
</body>
</html>

Exactly what I was look for, Thanks a lot Ray for you great great support!