while($row = mysql_fetch_array($query)){
if($row[c_ones]== $ones || $row[c_ones] == $ones-1 || $row[c_ones]==$ones+1){
$o_qishu[] = $o_qi.' ';
$o_qi = 0; }else{
$o_qi++;
} if($row[c_tens]== $tens || $row[c_tens] == $tens-1 || $row[c_tens]==$tens+1){
$t_qishu[] = $t_qi.' ';
$t_qi = 0; }else{
$t_qi++;
} if($row[c_hundreds]== $hundreds || $row[c_hundreds] == $hundreds-1 || $row[c_hundreds]==$hundreds+1){
$h_qishu[] = $h_qi.' ';
$h_qi = 0; }else{
$h_qi++;
} if($row[c_thousands]== $thousands || $row[c_thousands] == $thousands-1 || $row[c_thousands]==$thousands+1){
$th_qishu[] = $th_qi.' ';
$th_qi = 0; }else{
$th_qi++;
} if($row[c_ten_thousands]== $ten_thousands || $row[c_ten_thousands] == $ten_thousands-1 || $row[c_ten_thousands]==$ten_thousands+1){
$tt_qishu[] = $tt_qi.' ';
$tt_qi = 0; }else{
$tt_qi++;
}
} echo "<br>".max($o_qishu);
echo "<br>".max($t_qishu);
echo "<br>".max($h_qishu);
echo "<br>".max($th_qishu);
echo "<br>".max($tt_qishu);
}
输出数组时,都有很多比9大的数。可是不管怎么样max()都只返回9

解决方案 »

  1.   

    代码不完整,$o_qishu中的值是$o_qi相关的,但是$o_qi和你获取记录的个数相关,而不是和记录的值相关。
      

  2.   

    举例说明如下:
    if($row[c_ones]== $ones || $row[c_ones] == $ones-1 || $row[c_ones]==$ones+1){
    $o_qishu[] = $o_qi.' '; // 请问此处的$o_qi的初始值是多少?从你的代码中看不出来。
    $o_qi = 0; //符合条件的时候 $o_qi被重置为0;
    }else{
    $o_qi++; //不符合条件的时候$o_qi加1。
    }
    // 加下面这句打印出$o_qishu数组看看
    print_r($o_qishu);
      

  3.   


    $query = mysql_query("SELECT * FROM `data_c` order by `id` DESC");
    //这些事初始值
    $o_qi     = 0;
    $t_qi     = 0;
    $h_qi     = 0;
    $th_qi    = 0;
    $tt_qi    = 0;
    $o_qishu  = array();
    $t_qishu  = array();
    $h_qishu  = array();
    $th_qishu = array();
    $tt_qishu = array();print_r($o_qishu);//输出的结果符合要求//输出结果,数据太多在这里就只能发一小部分Array ( [0] => 1 [1] => 0 [2] => 0 [3] => 0 [4] => 11 [5] => 6 [6] => 10 [7] => 0 [8] => 2 [9] => 9 [10] => 0.............[5941] => 4 ) 
      

  4.   

    $o_qishu[] = $o_qi.' '; // 这里为什么要加'  '?去掉它结果是正确的。
      

  5.   

    呵呵,太感谢了。 没想到问题出在这里,太粗心了,花了我一个晚上的时间。开始时这样的echo $o_qi.' '//加个空格方便查看,后来把它赋给数组时忘了去除谢谢你,CunningBoy