i have 3 tables in mysql categories, subcategories, values.
now i want to get the values from categories table then count the number of values returned if it is greater than 0 then i fetch the category id from the categories table using while loop, next i check if the subcategory table has any data with the category id that i got from previous table if number of values is greater than 0 then i fetch the subcategory id from the subcategories table using while loop, now again i check the values table, if it has any data with subcategory id, if it is greater than 0 then i fetch all the values...
my code looks something like this...
$category_query = mysql_query("SELECT * FROM categories"); $num_category = mysql_num_rows($category_query); if($num_category > 0){ while ($row = mysql_fetch_object($category_query)) { $category_id[] = $row->category_id; $category_name[] = $row->category; $sub_query = mysql_query("SELECT * FROM subcategories WHERE category_id ='".$row->category_id."';"); $num_subcategory = mysql_num_rows($sub_query); if($num_subcategory > 0){ while ($sub_row = mysql_fetch_object($sub_query) { $subcategory_id[] = $sub_row->subcategory_id; $subcategory_name[] = $sub_row->subcategory; } for ($j=0; $j < $num_subcategory; $j++) { $subcategory_data[] = array("subcategory id"=> $subcategory_id[$j]); } } } for($i=0; $i<$num_category; $i++){ $category_data[] = array("category id"=>$category_id[$i], "category name"=>$category_name[$i],); }
i want to get the subcategory_data[] into category_data[]...........i cannot figure this out.. :-(