dongyong3223 2018-07-16 16:11
浏览 24
已采纳

从位置0开始而不是10

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);
  • 写回答

1条回答 默认 最新

  • dongshijiao2363 2018-07-18 20:40
    关注

    I changed my if condition to:

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

    That did the trick!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真