close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

How to create a nested JSON from two different MySQLi query?

Thread began 4/13/2022 4:20 pm by Rokon | Last modified 4/14/2022 4:54 pm by Rokon | 525 views | 11 replies

Rokon

Originally Said By: Ray Borduin
  
php:
<?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->ResultsJSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));    

?>    
</body>
</html>
  




Just a little more of your kind support further needed please. I am trying to just include the "chapterList" query under the "sectionList" query for one more step nested JSON. Please give me one more final push here to overcome the whole things. Thanks a lot Ray!

php:
<?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.SectionID, hadithsection.SectionBD FROM hadithsection WHERE hadithsection.BookID = ? ORDER BY hadithsection.SectionID ASC");
$sectionList->bindParam("i""".($hadithBooksList->getColumnVal("BookID"))  ."""-1"); //WAQB_Param1
$sectionList->execute();
?>
<?php
$chapterList 
= new WA_MySQLi_RS("chapterList",$hadithbd,0);
$chapterList->setQuery("SELECT hadithchapter.SectionID, hadithchapter.ChapterBG, hadithchapter.ChapterAR, hadithchapter.ChapterEN FROM hadithchapter WHERE hadithchapter.StatusActive = 1 AND hadithchapter.BookID = ? AND hadithchapter.SectionID = ? ORDER BY hadithchapter.chapID ASC");
$chapterList->bindParam("i""".($hadithBooksList->getColumnVal("BookID"))  ."""-1"); //WAQB_Param1
$chapterList->bindParam("i""".($sectionList->getColumnVal("SectionID"))  ."""-1"); //WAQB_Param2
$chapterList->execute();
?>
<?php
  $hadithBooksList
->Results[$hadithBooksList->Index]["Sections"] = $sectionList->Results;
  
$hadithBooksList->moveNext();
}
?>
<?php
header
("Content-Type: application/json; charset=UTF-8");

$json json_encode($hadithBooksList->ResultsJSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
    
//die(json_encode($hadithBooksList->Results, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));    
        
file_put_contents("hadith_books_section_chapter.json"$json);

?>

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...