I tried to insert some values into an array, but I don't know why I lost some values of them
This is the code I am using right now:
<pre><code>
<?php
include 'config/connections.php';
$SQL = "SELECT * FROM table";
$result = $db->query($SQL) or die("Couldn't execute
query.".mysqli_error($db));
$numresult=$result->num_rows;
for ($i=0; $i<$numresult; $i++)
{
$row = $result->fetch_assoc();
$c['id'] = 'H'.$i;
$c['start']= date("Y-m-d");
$a[$i] = $c;
for ($j=1; $j<4; $j++)
{
$c['id'] = 'H'.$i;
$c['start']= date('Y-m-d', strtotime("+".$j." days"));
array_push($a,$c);
}
}
echo json_encode($a);
?>
</pre></code>
Output:
[{"id":"H0","start":"2015-05-13"},
{"id":"H1","start":"2015-05-13"},
{"id":"H2","start":"2015-05-13"},
{"id":"H3","start":"2015-05-13"},
{"id":"H0","start":"2015-05-17"},
{"id":"H1","start":"2015-05-14"},
{"id":"H1","start":"2015-05-15"},
{"id":"H1","start":"2015-05-16"},
{"id":"H1","start":"2015-05-17"},
{"id":"H2","start":"2015-05-14"},
{"id":"H2","start":"2015-05-15"},
{"id":"H2","start":"2015-05-16"},
{"id":"H2","start":"2015-05-17"},
{"id":"H3","start":"2015-05-14"},
{"id":"H3","start":"2015-05-15"},
{"id":"H3","start":"2015-05-16"},
{"id":"H3","start":"2015-05-17"}]
I lost some values from array:
{"id":"H0","start":"2015-05-14"},
{"id":"H0","start":"2015-05-15"},
{"id":"H0","start":"2015-05-16"}
Any help in this regard is greatly appreciated!Thanks!
$c['start']= date('Y-m-d", strtotime("+".$j." days"));It shoulld be"Y-m-d".