how to extract data json format
<p>i retrieved data from mysql tables in json using php i.e</p>

<pre><code>$table_first = 'recipe';
$query = "SELECT * FROM $table_first";
$resouter = mysql_query($query, $conn);


$set=array();
while ($link = mysql_fetch_array($resouter, MYSQL_ASSOC)){
foreach ($link as $fieldname => $fieldvalue){
    $set[]= $fieldvalue;}
 $query2="SELECT ingredients.ingredient_id,ingredients.ingredient_name,ingredients.ammount FROM ingredients where rec_id = ".$link['rec_id'];
$result2 = mysql_query($query2, $conn);

 while ($rs = mysql_fetch_array($result2, MYSQL_ASSOC)){
     foreach($rs as $fieldname =>$fieldvalue){
         $set[]=$fieldvalue;
     }

 }

}
echo json_encode($set);</code></pre>

<p>The result of the code is </p>

<pre><code>["14","Spaghetti with Crab and Arugula","http:\/\/www","","2010-11-11 14:35:11","localhost\/pics\/SpaghettiWithCrabAndArugula.jpg",<br/>"7","13 ounces spaghetti","10 kg",<br/>"8","1 pound crabmeat","10"]
</code></pre>

<p>Note: The ingredients id starts after the image tag. 7 is the ingredient id followed by two fields "ingredients txt and amount" then 8 is another ingredient id relevant to the recipe id.
like there is no ({) open or (}) close bracket in my result.</p>

<p>what i want to do is to output it in a correct json format. i.e</p>

<pre><code>[
 {
  "rec_id": "14",
  "name":"Spaghetti with Crab and Arugula",
  "overview":"http:\/\/www",
  "category":"category",
                "time":"2010-11-11 14:35:11",
                "image":"localhost\/pics\/SpaghettiWithCrabAndArugula.jpg"
  "ingredients":
   {
    "ingredient":
     [                       {"ingredient_id":"7","ingredient_name":"13ounces spaghetti","amount":"10kg" },
{ "ingredient_id": "8", "ingredient_name": "1 pound crabmeat","amount":"10kg" },

     ]
   }]</code></pre>

<p>and same for recipe id 15 and so on.......</p>

<p>so how can get this....!! any suggestions</p>
