I am retrieving data from a mysql database and would like to return it as a JSON dict.
<?php
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = <<<SQL
SELECT tbldomainpricing.extension, tblpricing.msetupfee
FROM `tblpricing`
INNER JOIN tbldomainpricing ON tbldomainpricing.id = tblpricing.relid
WHERE tblpricing.type = 'domainregister'
SQL;
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
$all_rows = array();
while($row = $result->fetch_assoc()) {
$all_rows []= $row['extension'] . ":" . $row['msetupfee'];
}
header("Content-Type: application/json");
echo json_encode($all_rows);
?>
The return :
{"extension":".com","msetupfee":"6.99"},{"extension":".net","msetupfee":"6.99"},
How do I get the return to be
{"com":"6.99"},{"net":"6.99"}
Thanks