Q:

output jsonArray on php side, and decode on android

I have this php code:
if ($merchant_rows > 0){
    while($r=mysql_fetch_array($get_merchant)){
        $merchant_id = $r['merchant_id'];
    }

$sql = "SELECT quest_id, quest_title, quest_price, quest_points FROM quests WHERE merchant_id = '$merchant_id'";
$number = mysql_query($sql);
$rows = mysql_num_rows($number);

if ($rows > 0){
    while($result=mysql_fetch_array($number)){
        print(json_encode($result));
    }
}

and on the android side, after making an http post:
String res=response.toString();
jObject = new JSONObject(res);
                    JSONArray sessions = jObject.getJSONArray(res);
                for (int i = 0; i < sessions.length(); i++) {   
                JSONObject session = sessions.getJSONObject(i);  
                Quests quest = new Quests();    
                quest.quest_id = session.getString("quest_id");
                quest.title = session.getString("quest_title");
                String price = session.getString("quest_price");
                quest.dollar_price = "$"+price;
                String points = session.getString("quest_points");
                quest.pts = points + "pts";
                quests.add(quest);  }

My problem is that im trying to "getJSONArray" but I believe I'm not outputting the json as an array on the php side?

A:

use 
    mysql_fetch_array($result, MYSQL_ASSOC)
or 
    mysql_fetch_assoc()
when retrieve from assoiative keys else retrive from numeric keys.. 
if ($merchant_rows > 0){
    while($r=mysql_fetch_assoc($get_merchant)){
    $merchant_id = $r['merchant_id'];
}

$sql = "SELECT quest_id, quest_title, quest_price, quest_points FROM quests WHERE 
merchant_id = '".$merchant_id."'";
$number = mysql_query($sql);
$rows = mysql_num_rows($number);
$values = array();
if ($rows > 0){
    while($result=mysql_fetch_assoc($number)){
        array_push($values,  $result);}}

print json_encode($values);

