well sir i edit my code a little and it fulfill my requirement, like it retrieve first recipe then all the ingredient against that specific recipe and also all the instruction.
But the problem now is just the json format.
i show you my queries and my output
$result=array();
$table_first = 'recipe';
$query = "SELECT * FROM $table_first";
$resouter = mysql_query($query, $conn);
while ($recipe = mysql_fetch_assoc($resouter, MYSQL_ASSOC)){
$result[]=$recipe;
$query2="SELECT ingredients.ingredient_id,ingredients.ingredient_name,ingredients.ammount FROM ingredients where rec_id = ".$recipe['rec_id'];
$result2 = mysql_query($query2, $conn);
while($ingredient = mysql_fetch_assoc($result2)){
$result[]= $ingredient;
}
$query="SELECT instructions.instruction_id,instructions.instruction_text FROM instructions where rec_id = ".$recipe['rec_id'];
$resinner=mysql_query($query, $conn);
while($instruction= mysql_fetch_assoc($resinner))
{
$result[]=$instruction;
}
}
echo json_encode($result);
and the result for recipe id 14 is
[{“rec_id”:“14”,“name”:“Spaghetti with Crab and Arugula”,“overview”:“http:\/\/www”,“category”:“”,“time”:“2010-11-11 14:35:11”,“image”:“localhost\/pics\/SpaghettiWithCrabAndArugula.jpg”},{“ingredient_id”:“7”,“ingredient_name”:“13 ounces spaghetti”,“ammount”:“10 kg”},{“ingredient_id”:“8”,“ingredient_name”:“1 pound crabmeat”,“ammount”:“10”},{“ingredient_id”:“9”,“ingredient_name”:“7 ounces arugula, washed”,“ammount”:“10”},{“ingredient_id”:“10”,“ingredient_name”:“2 cloves garlic, finely chopped”,“ammount”:“10”},{“ingredient_id”:“11”,“ingredient_name”:“1 chili pepper, seeded and finely chopped”,“ammount”:“10”},{“ingredient_id”:“12”,“ingredient_name”:“4 tablespoons lemon juice”,“ammount”:“10”},{“ingredient_id”:“13”,“ingredient_name”:“6 tablespoons olive oil”,“ammount”:“10”},{“ingredient_id”:“14”,“ingredient_name”:“Salt and pepper to taste”,“ammount”:“10”},{“ingredient_id”:“55”,“ingredient_name”:“test”,“ammount”:“2 kg”},{“instruction_id”:“14”,“instruction_text”:“Cook spaghetti according to directions on package. Drain and set aside.”},{“instruction_id”:“15”,“instruction_text”:“In a large saucepan, heat olive oil. Add garlic and chili and saute for 30 seconds. Stir in crabmeat and lemon juice. Season with salt and pepper. Cook for 3-5 minutes, stirring constantly. Add arugula leaves.”},{“instruction_id”:“16”,“instruction_text”:“Add pasta and toss to coat. Adjust taste with salt and pepper if necessary. Serve immediately.”}
i just want to the ingredient array and instruction array should be inside the recipe array but look at my result when the recipe array finished then the ingredient array start
i want this to be inside in recipe array i.e
{“rec_id”:“14”,“name”:“Spaghetti with Crab and Arugula”,“overview”:“http:\/\/www”,“category”:“”,“time”:“2010-11-11 14:35:11”,“image”:“localhost\/pics\/SpaghettiWithCrabAndArugula.jpg”,
{then ingredient close here } and { instruction and recipe close here }}