I have this function:
public function findFavoriteMerchant($userId) {
// I grab all the merchant_id from favoriteMerchant where user_id = $userId
$q = $this->_db->prepare("SELECT * FROM favoriteMerchant WHERE user_id = ?");
$q->bindParam(1, $userId, PDO::PARAM_INT);
if ($q->execute()){
$result = $q->fetchAll(PDO::FETCH_ASSOC);
$i = -1;
foreach ($result as $row) {
$merchant = $this->_db->prepare("SELECT * FROM merchant WHERE merchant_id = ?");
$merchant->bindParam(1, $row["merchant_id"], PDO::PARAM_INT);
if ($merchant->execute()){
$i++;
$merchantArray[$i] = $merchant->fetchAll(PDO::FETCH_ASSOC);
}
}
return $merchantArray;
}
}
that return this :
[
[
{
"merchant_id": "17",
"business_name": "Nails Spa",
"merchant_first_name": "Jonh ",
"merchant_last_name": "Lampard",
"merchant_email": "email@me.com",
"merchant_address": "123 lampard street",
"merchant_country": "United States",
"merchant_city": "San Francisco ",
"merchant_state": "Dubai",
"merchant_postalCode": "92",
"merchant_telephone": "043251653",
"merchant_industry": "Beauty",
"merchant_type": "Spa",
"merchant_service": "other",
"merchant_lat": "37.804512",
"merchant_long": "-122.432335"
}
],
[
{
"merchant_id": "19",
"business_name": "Massage Spa",
"merchant_first_name": "carl",
"merchant_last_name": "smith",
"merchant_email": "email@me.com",
"merchant_address": "",
"merchant_country": "United States",
"merchant_city": "San Francisco ",
"merchant_state": "Dubai",
"merchant_postalCode": "92",
"merchant_telephone": "043278439",
"merchant_industry": "Beauty",
"merchant_type": "Spa",
"merchant_service": "other",
"merchant_lat": "25.037189",
"merchant_long": "55.251812"
}
]
]
but I would like to get this:
[
{
"merchant_id": "17",
"business_name": "Nails Spa",
"merchant_first_name": "Jonh ",
"merchant_last_name": "Lampard",
"merchant_email": "email@me.com",
// and so on....
****UPDATE****
$merchant = new Merchant();
echo json_encode($merchant->findFavoriteMerchant($userId),JSON_PRETTY_PRINT);
print r returns:
Array
(
[0] => Array
(
[merchant_id] => 17
[business_name] => Massage Spa
[merchant_first_name] => Jonh
[merchant_last_name] => Lampard
[merchant_email] => email@me.com
[merchant_address] => 123 lampard street
[merchant_country] => United States
[merchant_city] => San Francisco
[merchant_state] => Dubai
[merchant_postalCode] => 92
[merchant_telephone] => 043251653
[merchant_industry] => Beauty
[merchant_type] => Spa
[merchant_service] => other
[merchant_lat] => 37.804512
[merchant_long] => -122.432335
[merchant_userName] => Aviation
[password] => cfc10a708f01fe27750e3be246ca1daa
)
)
Array
(
[0] => Array
(
[merchant_id] => 19
[business_name] => Angsana Spa
[merchant_first_name] => carl
[merchant_last_name] => smith
[merchant_email] => email@me.com
[merchant_address] =>
[merchant_country] => United States
[merchant_city] => San Francisco
[merchant_state] => Dubai
[merchant_postalCode] => 92
[merchant_telephone] => 043278439
[merchant_industry] => Beauty
[merchant_type] => Spa
[merchant_service] => other
[merchant_lat] => 25.037189
[merchant_long] => 55.251812
)
)
I tried several approaches but I don't get it