Say I have a database which has the following layout:
Fields: |Business_Name| |Business_ID|
Data : |business_1A | |ABC_1 |
I want to query the database and retrieve the business name and business ID at the same time and then encode this result to JSON for further usage.
How do I go about doing this?
Here’s some code as requested:
$sql = "SELECT Business_Name,Business_ID FROM biz_table";
$businessArray = array();
$bizResult = mysql_query($sql);
while($row = mysql_fetch_assoc($bizResult)) {
$businessArray[][] = $row['Business_Name']$row['Business_ID'];
}
$result = json_encode($businessArray);
echo $result;
Thanks in advance!
Based on your question – your question was “how do i do that?” without really giving an example of the output you want :
$result will be
{"business_1A" : "ABC_1" }Is that what you want ?