I have 2 records, I want to show a single record as they have same email ID and different orderId and payments date.I am stuck with this and could not move forward. Please help me, I really need it. I do not want to repeat userinfo two times as email and name are repeating, I just want order to come under one array.
public function getDashboardData() {
$return = array();
$return['userInfo'] = array();
$temp = array();
if ( isset($this->data['userInput']) && strlen($this->data['userInput']) > 3 ) {
$userInput = $this->data['userInput'];
$bindArr = ['userInput' => "%".$userInput."%" ];
$query = "SELECT ju.id,ju.name,ju.email,ep.date,ep.newDateFormat,ep.packID, FROM joomla_users ju LEFT JOIN examPayments ep ON ep.email = ju.email WHERE ep.phone LIKE :userInput AND ep.isActive=1 GROUP BY ep.id ";
$sql = $this->PDO->runQuery($query,$bindArr);
if($this->PDO->prepRowCount($sql) > 0) {
while( $row = $this->PDO->prepFetch($sql) ){
$temp['name '] = $row['name'];
$temp['email'] = $row['email'];
$temp['order'][] = array(
'date' => array(
'startDate' => date('jS, F Y',strtotime( $row['date']))
),
'order' => array(
'orderID' => $row['orderID']
)
);
$status = TRUE;
array_push($return['userInfo'], $temp);
}
$return['status'] = TRUE;
return $return;
}else {
$return['status'] = FALSE;
$return['message'] = "No Records Found";
}
}else{
$return['status'] = FALSE;
$return['message'] = "Data Type Error";
}
return $return;
}
My Output
{
"userInfo": [
{
"name\t": "Kunal ",
"email": "[email protected]",
"order": [
{
"date": {
"startDate": "7th, August 2019",
"paymentDate": "7th, August 2019",
"expiryDate": "7th, August 2019"
},
"order": {
"orderID": "fsdfdsfdsfdsfsdfsdfsf"
}
}
]
},
{
"name\t": "Kunal ",
"email": "[email protected]",
"order": [
{
"date": {
"startDate": "7th, August 2019",
"paymentDate": "7th, August 2019",
"expiryDate": "7th, August 2019"
},
"order": {
"orderID": "dfdsfsfdsfsdfdsfsdfdfs"
}
}
]
}
]
}
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/
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.