Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何确定while循环中tep\u db\u fetch\u数组的大小?_Php_Mysql_Arrays_Count_Oscommerce - Fatal编程技术网

Php 如何确定while循环中tep\u db\u fetch\u数组的大小?

Php 如何确定while循环中tep\u db\u fetch\u数组的大小?,php,mysql,arrays,count,oscommerce,Php,Mysql,Arrays,Count,Oscommerce,我拿不到这个。 如何确定while循环中tep\u db\u fetch\u数组的大小 我想这样做: $i=0; while($a = tep_db_fetch_array($query)){ if($i==5){ // start a div i.e. } //do sth here if($i>=count($a)){ //close the div i.e. } $i++; } 但它不起作用,因为$a不是整个数组,只是指

我拿不到这个。 如何确定while循环中tep\u db\u fetch\u数组的大小

我想这样做:

$i=0;
while($a = tep_db_fetch_array($query)){
  if($i==5){
    // start a div i.e.
  }
  //do sth here
  if($i>=count($a)){ 
    //close the div i.e.   
  }
  $i++;       
}

但它不起作用,因为$a不是整个数组,只是指向实际查询结果的指针。我做错了什么,或者怎么做?

尝试函数tep\u db\u num\u rows,如下所示:

$i=0;
while($a = tep_db_fetch_array($query)){
  //do sth here
  if($i>=tep_db_num_rows($query)){ 
    //do sth other here for the last entry   
  }
  $i++;       
}

由于FrankZ论证,这是最简单的解决方案:

$i=0;
while($a = tep_db_fetch_array($query)){
  if($i==5){
    // start a div i.e.
  }
  //do sth here
  $i++;       
}
if($i>=5){ 
  //close the div i.e.   
}

出于好奇,我真是太他妈了:你为什么不在while循环之后再做呢?变量$a应该包含最后一条记录。因为第一个初始元素是在循环中完成的,所以仍然可以工作。是的,你是对的!我忘了一件重要的事!非常感谢你!就这样!