I have table store_profile
like this
id Storename Storetype address
1 Samsung Store Electronics Delhi
2 Levi Clothing Mumbai
3 Soni Electronics Bangalore
and second table Offers
id Store_id offer price
1 Samsung Store flat 30% off 20000
2 Levi Exchange 5000
3 Samsung Store Exchange offer 40000
I want to get all the store details from store_profile
for particular type,say Electronics and for each store their offers in single row,not repeated as I am getting from this syntax in json mysql query is :-
SELECT * , Offers.Store_id
FROM Store_profile INNER JOIN
Offers
ON Store_profile.Storename = Offers.Store_id AND
Store_profile.Storetype like '%Electronics%'
Here is my php code
$sql ="SELECT * , Offers.Store_id FROM Store_profile INNER JOIN Offers ON Store_profile.Storename = Offers.Store_id AND Store_profile.Storetype like '%Electronics%' LIMIT 0 , 300 ";
$r = mysqli_query($con,$sql);
$result = array();
while($row = mysqli_fetch_array($r)){
array_push($result,array(
'Store_Name'=>$row['Storename'],
'Store_address'=>$row['address'],
'Offer_Title'=>$row['offer'],
'MRP_Price'=>$row['price'],
)
);
}
echo json_encode(array('result'=>$result));
mysqli_close($con);