I have a table with a list of businesses. Each row has details such as the business name, ID, area,number just to mention a few.
I am querying the mysql database and currently i'm only retrieving the business name and ID.
I am then using the json_encode function to get an output like: {"BusinessA":"business_A_ID","BusinessB":"business_B_ID"}
I would like to be able to retrieve all of the business details and use the json encode function to get an output like:
[
{
"businessName": "BusinessA",
"businessID": "business_A_ID"
},
{
"businessName": "BusinessB",
"businessID": "businees_B_ID"
}
]
Here is the current code i'm using:
$businessRow = array();
$businessResult = mysql_query("SELECT * FROM businessTable");
while($row = mysql_fetch_assoc($businessResult)) {
$businessRow[$row['businessName']] = $row['businessID'];
}
$result = json_encode($businessRow);
echo $result;
So my question is what do I need to change this line to :
$businessRow[$row['businessName']] = $row['businessID'];
in order to get the above JSON output?
Thanks