重复PHP中的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);

毫无意义地放置这一行:

$n = mysql_num_rows($select_num_sub);
$smarty->assign('n',$n);

内部循环内。如果要通过Smarty显示查询的行数,只需进行:

$select_num_sub = mysql_query("SELECT * FROM market WHERE sub_cat='".$row_sub['id']."' 
$n = mysql_num_rows($select_num_sub);
$smarty->assign('n',$n);

在外循环内,你会没事的。

mysql_num_rows函数用于计数表中的行,因此它将在while-loop之前使用。

$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']."'  ");
  $n = mysql_num_rows($select_num_sub);
  while($row_num_sub = mysql_fetch_array($select_num_sub))
  {
    $smarty->assign('n',$n);
  }
 $sub_cats[] = $row_sub;
}
$smarty->assign('sub_cats',$sub_cats);

相关内容

  • 没有找到相关文章

最新更新