Forum Moderators: coopster

Message Too Old, No Replies

INSERT into MySQL Database Question

         

jeffgman

6:39 pm on Aug 16, 2004 (gmt 0)

10+ Year Member



I have an array, which I use the following insert line to insert the values into a MySQL database. Is it possible for me to only insert the lines where $ordery_qty is greater than 0 (zero)?

foreach($order_qty as $id_no => $val) {

$detailqry = "INSERT INTO whse_order_detail (order_no, id_no, sku, order_qty, order_date, store) VALUES ('$order_no', '$id_no', '$sku', '".$order_qty[$id_no]."', '$today', '$store')";
mysql_query($detailqry, $conn) or die(mysql_error() . "<BR>" . $detailqry);
}

Thanks,
Jeff

Timotheos

6:50 pm on Aug 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should work...

foreach($order_qty as $id_no => $val) {

if ($order_qty[$id_no] > 0) {

$detailqry = "INSERT INTO whse_order_detail (order_no, id_no, sku, order_qty, order_date, store) VALUES ('$order_no', '$id_no', '$sku', '".$order_qty[$id_no]."', '$today', '$store')";
mysql_query($detailqry, $conn) or die(mysql_error() . "<BR>" . $detailqry);

}

}

jeffgman

6:56 pm on Aug 16, 2004 (gmt 0)

10+ Year Member



I hate it when it looks so easy. I can't believe I did not think of something like that. Thanks for the help.

Jeff

Timotheos

8:06 pm on Aug 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Whew, I thought it might be a trick question ;-)

I can't believe how many times another set of eyes finds the problem so quickly after I've beens staring at it for hours.