0

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] => )

4

1 回答 1

0

这可能是由于两个原因:-

city 表中没有与您的查询匹配的行,因此它返回空值。

在经销商表的情况下,它可能会返回所有值当前为空的行。

请检查!

于 2013-08-09T07:04:33.047 回答