可能重复:
循环时我无法在里面创建 num 行
我尝试在循环中分配 num 行以获取另一个表的行数
$select_sub_cat = mysql_query("SELECT * FROM sub_cat WHERE ct_id='".$row_main['id']."' LIMIT 8 ");
while($row_sub = mysql_fetch_array($select_sub_cat))
{
$select_num_sub = mysql_query("SELECT * FROM market WHERE sub_cat='".$row_sub['id']."' ");
while($row_num_sub = mysql_fetch_array($select_num_sub))
{
$n = mysql_num_rows($select_num_sub);
$smarty->assign('n',$n);
}
$sub_cats[] = $row_sub;
}
$smarty->assign('sub_cats',$sub_cats);