douliangli6407 2014-11-29 21:41
浏览 32

使用逗号分隔值更新表中的值?

I have some contents that are sent to me with php://input that looks like this:

123,567,287,124,172,846,372,187

And I want to update a table based on this, so something like this

UPDATE char_
SET id=123
WHERE SortNumber=1

Now, I think I can do something like this

$variable=123,567,287,124,172,846,372,187
$anothervariable=$variable = str_replace(",", "
", $variable); 


$i=0;
$i++;

 mysqli_query(UPDATE char_ SET id=$anothervariable WHERE SortNumber=$i)

But, I'm not sure that the code is 100 correct AND, the variable will be the whole contents and I dont know how I can set a different variable to every line? Any help?

  • 写回答

2条回答 默认 最新

  • dongsheng8158 2014-11-29 21:46
    关注

    I have no idea about PHP but can give you a rough idea with a sample pseudo code. Store all those numbers in a array (probably integer array) and loop through the array and call the UPDATE statement. Hope that makes sense

    int[] arr = {123,567,287,124,172,846,372,187};
    
    for(int i = 0; i < arr.length; i++)
    {
      UPDATE char_ SET id=arr[$i] WHERE SortNumber=$i
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示