Here, I will show what I tried, here is my code:
<?php
require('../db_connection.php');
$data = json_decode(file_get_contents("php://input"));
// $groupId = $data->groupId;
$groupId = '0000000001';
$menus = array();
$items = array();
$query = mysqli_query($db_conn, "SELECT DISTINCT module_id, module_name_eng
FROM v_usergroupappitems
WHERE group_id = '".$groupId."' AND module_active = 1 ORDER BY module_id");
while ($modules = mysqli_fetch_assoc($query)) {
$menus[] = $modules;
$module_id = $modules['module_id'];
$items_query = mysqli_query($db_conn, "SELECT item_id, item_name_eng, page_link
From v_usergroupappitems
WHERE module_id = '$module_id'
AND group_id = '".$groupId."'
AND active = 1 ORDER BY 'item_id' ");
while ($item_list = mysqli_fetch_assoc($items_query)) {
$items[] = $item_list;
array_push($menus, $items);
}
}
// echo $rows;
echo json_encode($menus);
?>
I could return an array of modules using:
$menus[] = $modules;
like this:
[{"module_id":"1","module_name_eng":"Application Administration"},{"module_id":"2","module_name_eng":"Outpatient Data Setup"},{"module_id":"3","module_name_eng":"Medical Insurance Companies"},{"module_id":"4","module_name_eng":"Outpatient Section"},{"module_id":"5","module_name_eng":"Outpatient Doctors` Fees"},{"module_id":"6","module_name_eng":"Patient Visit Medical Records"},{"module_id":"7","module_name_eng":"Inpatient Data Setup"},{"module_id":"8","module_name_eng":"Inpatient Section"},{"module_id":"12","module_name_eng":"Money Setup-Transactions-Reports"}]
what I need is to add each module items as array inside its object, just like that:
[{"module_id":"1","module_name_eng":"Application Administration", "items": [{"item_id":"1","item_name_eng":"Company Data","page_link":"link1"},{"item_id":"2","item_name_eng":"User Groups","page_link":"link2"}]}]
but my problem is: i am getting that:
[{"module_id":"1","module_name_eng":"Application Administration"},[{"item_id":"1","item_name_eng":"Company Data","page_link":"..\/sa\/company.php"}],[{"item_id":"1","item_name_eng":"Company Data","page_link":"..\/sa\/company.php"},{"item_id":"2","item_name_eng":"User Groups","page_link":"\/dashboard\/usergroupslist"}],[{"item_id":"1","item_name_eng":"Company Data","page_link":"..\/sa\/company.php"},{"item_id":"2","item_name_eng":"User Groups","page_link":"\/dashboard\/usergroupslist"},{"item_id":"3","item_name_eng":"System Users","page_link":"..\/SA\/user.php"}],[{"item_id":"1","item_name_eng":"Company Data","page_link":"..\/sa\/company.php"},{"item_id":"2","item_name_eng":"User Groups","page_link":"\/dashboard\/usergroupslist"},{"item_id":"3","item_name_eng":"System Users","page_link":"..\/SA\/user.php"},{"item_id":"64","item_name_eng":"Users System Login","page_link":"..\/sa\/rpt_users_login.php"}],[{"item_id":"1","item_name_eng":"Company Data","page_link":"..\/sa\/company.php"},{"item_id":"2","item_name_eng":"User Groups","page_link":"\/dashboard\/usergroupslist"},{"item_id":"3","item_name_eng":"System Users","page_link":"..\/SA\/user.php"},{"item_id":"64","item_name_eng":"Users System Login","page_link":"..\/sa\/rpt_users_login.php"},{"item_id":"65","item_name_eng":"User System Login","page_link":"..\/sa\/rpt_user_login.php"}],{"module_id":"2","module_name_eng":"Outpatient Data Setup"},[{"item_id":"1","item_name_eng":"Company Data","page_link":"..\/sa\/company.php"},{"item_id":"2","item_name_eng":"User Groups","page_link":"\/dashboard\/usergroupslist"},{"item_id":"3","item_name_eng":"System Users","page_link":"..\/SA\/user.php"},
that is not the structure i need to get, i need the following structure:
[{"module_id":"1","module_name_eng":"Application Administration", "items": [{"item_id":"1","item_name_eng":"Company Data","page_link":"link1"},{"item_id":"2","item_name_eng":"User Groups","page_link":"link2"}]}]
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
DBMS is a database management system. It is designed to change, search, add and delete information in the database. There are many DBMSs designed for similar purposes with different features. One of the most popular is MySQL.
It is a software tool designed to work with relational SQL databases. It is easy to learn even for site owners who are not professional programmers or administrators. MySQL DBMS also allows you to export and import data, which is convenient when moving large amounts of information.
https://www.mysql.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.