OK here’s the scenario: previous php page was showing a list of items like so:
ItemName… Image of Item
where the is a checkbox input type of the Item ID.
Next page receives the array of Item IDs and does a for each {} and assembles a delimited list of ItemIDs as a single string. (Never mind why; just assume that’s the end goal for now).
$ccount = 0;
$ResList = '';
for ($i = 0; $i< $ccount; $i++) {
$ResList = $ResList . '::' . $ItemID[$i];
}
$ResList = $ResList . '::';
Works fine, and all is well with the world.
Well, now it would be useful to have a separate value per each line item for QUANTITY.
OK, I thinks to myself, easy enough, input type is text, value is 1 by default. Then on the next page I wrap my for each {} thingie in an IF that says If $ItemID[$i] > 0, so that it only deals with the ItemID and the Quantity for that line item if there is indeed a check in the checkbox for ItemID, thus ignoring all those default Quantity=1 values for the items NOT checked, right?
$ccount = 0;
$ResList = '';
$QtyList = '';
for ($i = 0; $i< $ccount; $i++) {
If ($ItemID[$i] > 0) {
$ResList = $ResList . '::' . $ItemID[$i];
$QtyList = $QtyList . '::' . $qquantity[$i];
}
}
$ResList = $ResList . '::';
$QtyList = $QtyList . '::';
WRONG. When ItemIDs 1, 2, and 4 were checked off (skipping item 3) and quantities input were 2, 1, 1, and 5 for ItemIDS 1, 2, 3, and 4, I first ended up my two result strings looking like this:
$ResList: ::1::2::4::
$QtyList: ::2::1::1::
I tried removing the default value 1 from item 3 and ran it and got this:
$ResList: ::1::2::4::
$QtyList: ::2::1::::
I don’t suppose there’s any standard HTML for “If not empty, <input type=text name=qquantity” perchance?
I’ve thought about ditching the checkbox fields altogether, setting input type to hidden, but then everything gets ordered. Or if I removed default value for quantity and used If to only append quantities when quantity > 0, it seems like that would work EXCEPT that that’s the same logic that’s not working right above for only accepting quantities when ItemID isn’t empty ?!??
I’ve tried concatenating the values of $ItemID[$i] and $qquantity[$i] with a second delimiter and assembling a single string but ended up with a single-string version of the same problem (when it skips over the empty value for ItemID it doesn’t also skip over the quantity so they’re still misaligned).