php嵌套的do-while循环在第一次迭代后终止

时间:2016-02-03 04:52:29

标签: php do-while

我正在使用嵌套的do-while循环来访问两个json结果,不幸的是循环在第一次迭代后终止,它返回外部循环json结果而不执行内部循环。请找到使用嵌套do-while循环的函数:

public function data_report($fromdate, $todate)
{
  $lp = new log_report();
  $mysqli = new mysqli("172.16.10.102", "aventador", "RND@ISO-3306", "eTrans");
  if ($mysqli->connect_errno) 
  {
      $response["success"] = 0;
  }
  if (!$mysqli->multi_query("call sp_Android_Online_Dashboard('$fromdate','$todate')")) 
  {
      $response["success"] = 0;
  }

  else {
    //1st Iteration 
  do {  
    if ($res = $mysqli->store_result()) 
    {
        $response["values"] = array();  
        while ($row = $res->fetch_assoc()) 
        {
            $i=1;
            $value = array();
            $value["location_name"] = $row["location_name"];
            $value["location_id"] = $row["location_id"];
            $value["Totfiles"] = $row["Totfiles"];
            $arr = explode(":", $row["file_minutes"], 2);
            $value["file_minutes"] = $arr[0];
            $value["Total_Lines"] = round($row["Total_Lines"], 0, PHP_ROUND_HALF_UP);

            array_push($response["values"], $value);    

            echo $i++;
        }   
    if (!$mysqli->multi_query("call sp_get_Android_Online_minutes_Chart('$fromdate','$todate')")) 
    {
            $response["success"] = 0;

    }

    //2nd Iteration
    do {
            if ($res = $mysqli->store_result()) 
            {
                $response["Chart_data"] = array();  

                while ($row = $res->fetch_assoc()) 
                {
                    $j=5;
                    $value = array();
                    $value["File_Day"] = $row["FileDay"];
                    $value["File_Minutes"] = $row["Tot_minutes"];
                    array_push($response["Chart_data"], $value);    

                }
                    $response["success"] = 1; 
                    echo json_encode($response, JSON_NUMERIC_CHECK);
                    $res->free();
                }

                echo $j++;

               } while($mysqli->more_results() && $mysqli->next_result());
           }

            echo json_encode($response, JSON_NUMERIC_CHECK);    

        } while($mysqli->more_results() && $mysqli->next_result()); 
    }
  }

请提前帮助我解决这个问题!!

0 个答案:

没有答案