我需要从两个表中获取数据,一个是类别表,第二个是子类别表。在子类别表中,我正在保存类别表的主键。现在我需要从表中获取数组。首先我想显示类别名称及其子类别,然后是第二个类别及其子类别。这是我获取类别和子类别列表的代码。
include("admin/common/connection.php");
$userId= $_GET['user'];
if(isset($userId))
{
$select="select category_name,id from tbl_category where user_id='".$userId."'";
$query= mysql_query($select);
$var= array();
while($fetch_row= mysql_fetch_array($query))
{
$cat_dish= $fetch_row['category_name'];
$var['category'] = $cat_dish;
$select_dish="select dish_photo,printer_location,printer_list,kitchen_display from tbl_category_dish where user_id='".$userId."' and cat_id='".$fetch_row['id']."'";
$query_dish= mysql_query($select_dish);
while($row= mysql_fetch_array($query_dish))
{
$var['dish_photo']= $row['dish_photo'];
$var['printer_location']= $row['printer_location'];
}
}
print_r($var);
}