doujiebo9849 2015-11-18 04:19
浏览 45
已采纳

将$ i连接到变量名称的结尾

I'm trying to make it so that each time I loops through, the SQL statement changes to reflect the value of I as well. For example, if there are two rows, I want it to execute an SQL statement with the variables product1, quantity1, unit1 and also for the variable proudct2,quantity2,unit2.

Unfortunately, all it does is evaluate the same sql statement twice. How do I go about fixing it?? Thanks

for ($i = 1;$i=$numrows; $i++) {
     $sql= "INSERT INTO orderItem(order_id,item_linenum,product_id,item_quantity,item_unitprice)
          VALUES(".$_REQUEST["orderNumber"]."$i,'".$_REQUEST["product".$i]."','".$_REQUEST['quantity'.$i]."'," .$_REQUEST['unit'.$i].")";
    print "*" . $sql. "*" . "<br/>";
    $result= mysqli_query($db, $sql) or die("SQL error: " . mysqli_error());
}
  • 写回答

1条回答 默认 最新

  • dongzhong7443 2015-11-18 04:25
    关注

    Change this,

    for ($i = 1;$i <= $numrows; $i++) {
                   ^
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?