duanjia2415 2017-08-25 17:27
浏览 34
已采纳

PHP从值X创建X量的MySQL条目

I need some assistance with a project, I am clueless on creating this type of advanced code that I need to complete the project.

I retrieve a certain value "X" (1 - 1000), and need to create the same amount of MySQL entries of the value "X", each entry has different information, this is retrieved through JSON url.

Here is the data I retrieve that I need to save to the database:

1. Title (Does not change)
2. ID (New ID with each value "X", eg, 1 = itv23, 2 = itb12 ...)
4. Detail (Changes per ID)

I have a working JSON Phrase, however dont know how to automate the entries to the database so that it creates the "X" amount of entries to a certain Table in the Database.

  • 写回答

1条回答 默认 最新

  • dongmanzui8486 2017-08-25 17:49
    关注

    With the information you gave is a little bit difficult to answer but I thin this at least will give you a boost

    $titles = array("title1", "title2", "title3",....);
    $details = array("details1","details2","details3",....);
    $times = $X;
    
    foreach ($times as $time){
      $id = $time. "something";
      $title = $titles[$time];
      $detail = $details[$time];
      mysql_query("INSERT INTO tableName (id,title,details) 
      VALUES ('$id', '$title',$details)");
    }
    

    I didn't quite understand the JSON part but if you have a JSON you can decode it and use it in PHP like this:

    $json = '{"a":1,"b":2,"c":3,"d":4,"e":5,.....}';
    $jsonTophp = json_decode($json);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100