How to format a query result set as a JSON string
02:18 28 Mar 2011

I need to get an array output as this [[1, 26], [3, 16], [3, 17], [4, 27], [4, 26]] from the following php mysql code

    include("db.php");

$villa = $_GET['villa'];

$sql = mysql_query("SELECT unavailable_date_from, unavailable_date_to FROM villa WHERE name = '".$villa."'");
$json = "[";
    while($results = mysql_fetch_object($sql)){
        
        foreach ($results as $field => $value) {
            $a = explode("-", $value);
                
            $json = $json . '[' . $a[1] .','. $a[2] .'],';
        }
    
        $json = substr($json, 0, strlen($json)-1);
        
    }

$json = $json . ']';
    
echo $json;

The current code give the following result: [[03,08],[03,10][03,15],[03,20]]

How can I add that one comma between the second and third array element?

php mysql json resultset