Re: put a lot of items in a shopping cart at once



You have to use an associative array to accomplish that. You put in the
quantity specification form items like this:

<input type='text' name='itemqty[72132]' value="" />

and then, the quantity inserted in the field by the user will be in the
other part of the array, so basically you will get, when posting this
form back, an array like:

"itemqty[7132]" -> "1", "itemqty[3245]" -> "1", ...

and then se a for each loop with key and value (key is 7132, 3245) and
value is the quantity entered in the field:

$itemqty = $_POST["itemqty"];
while (list ($key, $val) = each ($itemqty)) {
if ($val <> "0") {
$upq = "insert into `shopping_cart` values ( `quantity` =
'$val') where `item_id` = '$key'";
};
$upr = mysql_query($upq) or die ("Cannot INSERT quantities:
".mysql_error());
};

....i hope this helps.

.



Relevant Pages

  • Re: best practice if then else
    ... Is the best way to accomplish this a long list of ... the value of the element of the array Arr corresponding to the selected ... buttons select which Easter function is to be tested (years in error, ...
    (comp.lang.javascript)
  • Referencing Variables By Name in a String
    ... so creating them in an array isn't really an option. ... There are several variable groups like this - this is only one of them. ... <now start the code referencing this item> ... Does anyone know a way to accomplish something like this. ...
    (comp.lang.ruby)
  • Re: preg_replace help
    ... Maybe I'm just a G group newbie. ... the buffer are links to user profiles that are composed with the user ... a full search and replace array for every user id especially ... accomplish this using regular exp like this: ...
    (alt.php)
  • Re: Deallocating storage
    ... milkyway wrote: ... I am setting an item in an array to ... to unneeded objects, but you don't necessarily need to explicitly set ... variables or array slots to null to accomplish that. ...
    (comp.lang.java.help)
  • Re: Slow Array formula or is there any alternative
    ... array entered to accomplish the intended purpose. ... there's no need to enter this as an array formula. ... >> and I need to do a lookup against some other lookup table. ... >> Basically, it says if a value is found in the W2Ord table, then do a ...
    (microsoft.public.excel.programming)