0

i have an result from mysql query and i can able fetch data and push to normal array format and also encoded as json and my output looks like

here is my php code

$query1 = mysql_query($myquery1);
if ( ! $query1 ) {
    echo mysql_error();
    die;
}

$data1 = array();
for ($x = 0; $x < mysql_num_rows($query1); $x++) {
    $data1[] = mysql_fetch_assoc($query1);
}
echo json_encode( $data1);

Where myquery1 has the result from mysql select statement

My json result is

 [{"Date":"2017-12-01","users":"5","d0":"5","d1":"0","d2":"0","d3":"0","d4":"0"},
 {"Date":"2017-12-02","users":"0","d0":"0","d1":"0","d2":"0","d3":"0","d4":"0"},
 {"Date":"2017-12-03","users":"0","d0":"0","d1":"0","d2":"0","d3":"0","d4":"0"},
 {"Date":"2017-12-04","users":"1","d0":"1","d1":"0","d2":"0","d3":"0","d4":"0"},
 {"Date":"2017-12-05","users":"1","d0":"1","d1":"0","d2":"0","d3":"0","d4":"0"},
 {"Date":"2017-12-06","users":"1","d0":"1","d1":"0","d2":"0","d3":"0","d4":"0"}]

My expected result has to like this , how can i achieve this

 [{"Date":"2017-12-01","users":"5","d0":"5","d1":"0","d2":"0","d3":"0","d4":"0"},

  {"Date":"2017-12-02","users":"0","d0":"0","d1":"0","d2":"0","d3":"0"},

  {"Date":"2017-12-03","users":"0","d0":"0","d1":"0","d2":"0"},

  {"Date":"2017-12-04","users":"1","d0":"1","d1":"0"},

  {"Date":"2017-12-05","users":"1","d0":"1"},

  {"Date":"2017-12-06","users":"1"}]

I am a beginner in php, please do help with this

mega6382
  • 9,211
  • 17
  • 48
  • 69
White Rose
  • 11
  • 7
  • 1
    Kindly include your code in the question. Preferably, the code where you push to array – Goma Dec 18 '17 at 05:28
  • `mysql_*` is deprecated as of [tag:php-5.5] and removed as of [tag:PHP-7]. So instead use `mysqli_*` or `PDO`. [Why shouldn't I use mysql_* functions in PHP?](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/14110189#14110189) – mega6382 Dec 18 '17 at 05:34
  • You want blank lines between the data? – ryantxr Dec 18 '17 at 05:34
  • Blank lines means ? i need one value to be decremented in each line – White Rose Dec 18 '17 at 05:42

0 Answers0