循环时,我无法在内部生成num行

时间:2012-10-17 04:45:11

标签: php while-loop mysql-num-rows

我有两张桌子 第一表:适用于产品 第二个表:对于类别

我想在浏览器中显示

类别1(20) 类别2(5) category3(3)

$select_sub_cat = mysql_query("SELECT * FROM sub_cat WHERE ct_id='".$row_main['id']."' ");
while($row_sub = mysql_fetch_array($select_sub_cat))
{
  $select_num_sub = mysql_query("SELECT * FROM market WHERE sub_cat='".$row_sub['id']."' ");
  $row_num_sub = mysql_num_rows($select_num_sub);
  $smarty->assign('numb',$row_num_sub);

 $sub_cats[] = $row_sub;
}
$smarty->assign('sub_cats',$sub_cats);

2 个答案:

答案 0 :(得分:0)

试试这个:

$select_sub_cat = mysql_query("SELECT * FROM sub_cat WHERE ct_id='".$row_main['id']."' ");
while($row_sub = mysql_fetch_array($select_sub_cat))
{
  $select_num_sub = mysql_query("SELECT * FROM market WHERE sub_cat='".$row_sub['id']."' ");
  $smarty->assign('numb',$row_num_sub);

 $sub_cats[] = $row_sub;
 $sub_cats['count']=mysql_num_rows($select_num_sub);
}
$smarty->assign('sub_cats',$sub_cats);

答案 1 :(得分:0)

尝试

$select_sub_cat = mysql_query("SELECT * FROM sub_cat WHERE ct_id='".$row_main['id']."' ");
while($row_sub = mysql_fetch_array($select_sub_cat))
{
  $select_num_sub = mysql_query("SELECT * FROM market WHERE sub_cat='".$row_sub['id']."' ");         
 $sub_cats[] = $row_sub;
 $sub_cats['count']=mysql_num_rows($select_num_sub);
}
$smarty->assign('sub_cats',$sub_cats);

然后打电话给你的聪明人:

  

{$ sub_cats.name}({$ sub_cats.count})// $ sub_cats.name应该是类别的“名称”