繁体   English   中英

为插入的每一行插入数字+1

[英]insert number +1 for every row inserted

我有这个PHP脚本:

for ($i = 0, $count = count($ingredientQTY); $i < $count; $i++) {
            $yo = 1;
            $rows[] = array(
                'ingredientamount'         => $ingredientQTY[$i],
                'ingredientType' =>  $measurements[$i],
                'ingredientname'        => $ingredientNAME[$i],
                'recipe_id' => $recipe_id
            );
            $sql = "INSERT `ingredients` (`ingredientamount`,`ingredientType`,`ingredientname`, `recipe_id`) VALUES ";
            $coma = '';
            foreach ($rows as $oneRow) {
                $sql .= $coma."('".implode("','",$oneRow)."')";
                $coma = ', ';
            }
            $this->db->query($sql);
      }

      break;
}

它将一行(包含ingredientamount,ingredientType和ingrientname)插入表格成分中。 我还有一个从1开始的订单列,对于每个插入的行,添加1到订单 如何使用我当前的代码执行此操作? 我想也许我必须有一个隐藏的字段,我传入,但有没有办法用PHP做到这一点?

感谢所有的帮助,如果我描述的方式有任何混乱,请问!

你的循环已经有一个计数器$i ,只需插入$i + 1作为该字段的值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM