从位置0而不是10开始

时间:2018-07-16 16:11:31

标签: php

我正在从两个数据库表中生成一个.js文件,它工作得很好,但是现在我试图在$ .js文件的开头(位置0)而不是提醒(位置)10处启动$ results2。

我无法绕过这个头...感谢您的帮助!

$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);

1 个答案:

答案 0 :(得分:0)

我将if条件更改为:

$counter % 10 == 0) || $counter==1 

做到了!