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 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?