dow58115 2015-02-13 16:36
浏览 53
已采纳

如何反序列化数组并为每个数据插入查询?

I'm not used to work with arrays, and now i have to, and i need some help guys.

I have a list of absences,that contain multiples values. They are all ids (like 4,25,100...) separed by a ','.

I want to add every single id in a table (insert query),i know the simple methode :

Insert into table (columns..) Values(values1,value2,...), 
(values1,value2,...),
(values1,value2,...),
(values1,value2,...)

But i dont know how to use it the the serialsed array.

  • 写回答

1条回答 默认 最新

  • duanchi1230 2015-02-13 17:49
    关注

    Explode the string on the commas, then iterate over the resulting array. Understanding arrays is essential to PHP (and coding in general), so check out http://php.net/manual/en/language.types.array.php.

    $string = '4,25,100';
    $array = explode(',', $string);
    foreach ( $array as $value ) {
        $sql = "INSERT INTO `table` (`some_column`) VALUES ('".$v."')";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算