I'm generating a .js file from two database tables and it's working great but now I'm trying to start the $results2 at the beginning (position 0) of the .js file instead of reminder (position) 10.
I cannot wrap my head around this one... Any help is appreciated!
$result = $mysqli->query("SELECT id, username, name, content, image, cssanimate, group_name FROM TABLE1 ORDER BY id ");
$result2 = $mysqli->query("SELECT id, username, name, content, image, cssanimate, group_name FROM TABLE WHERE username = 'admin' ");
$records2 = array();
while ($row2 = $result2->fetch_assoc()) {
$records2[] = array('tags' => array($row2));
}
$counter = 0;
while ($row = $result->fetch_assoc()) {
$records[] = array('tags' => array($row));
$counter++;
if($counter % 10 == 0) {
$records = array_merge($records, $records2);
}
}
// Make is pretty
$json = json_encode($records, JSON_PRETTY_PRINT);
$data = 'var data = ';
file_put_contents('file.js', $data);
file_put_contents('file.js', $json, FILE_APPEND);
I changed my if condition to:
$counter % 10 == 0) || $counter==1
That did the trick!