Hi There-
Am trying to build a shopping cart program, here's a simplified version of my dilemma.
In the following code, I've set up four textfields to be put into an associative array:
<html>
<?PHP
if (!ISSET ($_POST['A']))
{
?>
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
1 <input type="text" name="A[1]" size = "3"><br>
2 <input type="text" name="A[2]" size = "3"><br>
3 <input type="text" name="A[3]" size = "3"><br>
4 <input type="text" name="A[4]" size = "3"><br>
<input type="submit" value="test array">
<?PHP
}
if (ISSET ($_POST['A']))
{
$A = $_POST['A'];
foreach ($A as $x => $y)
{
echo ("x = $x and y = $y <br>");
}
}
?>
</html>
If I input numbers into just two of the textfields, I get the following result:
x = 1 and y =
x = 2 and y = 4
x = 3 and y =
x = 4 and y = 7
What I'm trying to do is figure out how to get only those textfields that have answers to be in the array and if they don't have answers, leave them out.
One not-elegant solution I came up with involved checkboxes and if the checkbox for that particular row is checked, then that would get the resulting row from the array, but I'd really like to figure out how to do it so that it's just the textboxes and one click. Is there a way to get rid of 1 and 3 above, or have them not show up in the array at all?
I'm trying to build a shopping cart and have it be populated by data from another form. The textfield above (y) would be the quantity ordered and the keys would be the product_ID number from the database.
If there's no quantity ordered, I'd really like it so they don't show up in the table I build for the cart. It would be really dumb.
Thanks so much to whomever helps me.
Lee