无法获取查询以从数据库返回所有数据

时间:2017-08-30 11:27:54

标签: php

 <?php
    define('HOST','localhost');
    define('USER','id2553362_hcoe');
    define('PASS','admin');
    define('DB','id2553362_hamrosadhan');

    $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');

    $jsondata = file_get_contents("php://input");
    $data = json_decode($jsondata,true);

    $bookeduser = $data['BookedUser'];
    $bookfrom = $data['BookedFrom'];
    $bookto = $data['BookTo'];
    $category = $data['Category'];
    $ulat = $data['ULat'];
    $ulong = $data['ULong'];


   $sql = "SELECT PostId,VehicleName,VechicleID,Category,Location,  
    Description,RateAmount, AvailableFrom,AvailableTo, ( 6371 * acos( cos( 
   radians($ulat) ) * cos( radians(LocationLat ) ) * 
   cos( radians( LocationLong ) - radians($ulong) ) + 
    sin( radians($ulat) )* 
     sin( radians(LocationLat ) ) ) ) AS distance FROM VehicleDetails WHERE 
    Category='$category' AND AvailableFrom <= '$bookfrom' AND AvailableTo >= 
   '$bookto' HAVING distance < 500  ";

  $query = mysqli_query($con, $sql) or die('query fails');




    if($query){
            while($vinfo = mysqli_fetch_array($query))
                {

                        var_dump($vinfo);die;
                }

    }

    ?>

我希望我的代码使用查询过滤器返回表中的所有数据,但我的查询只返回1个数据。 输出:

                               array(20) {
  [0]=>
  string(1) "3"
  ["PostId"]=>
  string(1) "3"
  [1]=>
  string(5) "cbras"
  ["VehicleName"]=>
  string(5) "cbras"
  [2]=>
  string(11) "ba56psa2437"
  ["VechicleID"]=>
  string(11) "ba56psa2437"
  [3]=>
  string(8) "2 wheels"
  ["Category"]=>
  string(8) "2 wheels"
  [4]=>
  string(7) "gongabu"
  ["Location"]=>
  string(7) "gongabu"
  [5]=>
  string(12) "got conditon"
  ["Description"]=>
  string(12) "got conditon"
  [6]=>
  string(4) "5000"
  ["RateAmount"]=>
  string(4) "5000"
  [7]=>
  string(10) "2017-09-15"
  ["AvailableFrom"]=>
  string(10) "2017-09-15"
  [8]=>
  string(10) "2017-10-15"
  ["AvailableTo"]=>
  string(10) "2017-10-15"
  [9]=>
  string(18) "0.8621561884069938"
  ["distance"]=>
  string(18) "0.8621561884069938"
}

this is my database

1 个答案:

答案 0 :(得分:1)

取下模具;来自while循环,并把它放在}

下面
if($query){
    while($vinfo = mysqli_fetch_array($query)) {

        var_dump($vinfo);
    }

    die();
}