简体   繁体   中英

MySql empty result set returns different formats

I am trying to execute two simple select queries on two different tables in mysql server. This I am doing this by running a php script. Both the queries are supposed to return an empty result set. But they are returning different formats.

City table is returning a simple null value where as Dealer table is returning all columns with null values.

Output:

{**"dealer"**:[{"car_make":null,"state":null,"city":null,"company_name":null,"company_address":null,"phone":null,"mobile":null,"fax":null,"email":null,"website":null,"Data_Version":null}],**"city"**:null}

PHP Script

<?php

$data_version = 5;

require 'DbConnect.php';


$query = ("SELECT * FROM `Dealer` WHERE `Data_Version` > $data_version");


if ($query_run = mysql_query($query)){

    while ($query_row = mysql_fetch_assoc($query_run)){

        $out [] = $query_row;

    }

}
else{
    echo 'Fail';
} 


$query1 = ("SELECT * FROM `City` WHERE `Data_Version` > $data_version");


if ($query_run1 = mysql_query($query1)){

    while ($query_row1 = mysql_fetch_assoc($query_run1)){

        $out1 [] = $query_row1;

    }

}
else{
    echo 'Fail';
} 


$Output=array('dealer'=>$out,'city'=>$out1); 

    echo(json_encode($Output));

?>

So due to the varying formats i am not able to handle it. What is the reason for such varying formats? What should I do to have same kind of results??

Table Schemea

Dealer table "car_make","state","city","company_name","company_address","phone","mobile","fax","email","website","Data_Version"

City Table

city, state, Data_Version

(All fields are Varchar(50) )

Output of printing

Array ( [dealer] => Array ( [0] => Array ( [car_make] => [state] => [city] => [company_name] => [company_address] => [phone] => [mobile] => [fax] => [email] => [website] => [Data_Version] => ) )[city] => )

It might be possible due to two reasons:-

There is no row that match your query in city table so it return null value.

In case of dealer table it might be returning a row in which all values are currently null.

Please check!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM