I have been attempting to pass a series of dynamically generated html textbox variables into an array. This is for a shopping cart with the textbox beside every product so the person can enter a quantity of something they desire to purchase. The code below works, but I can only get the last value to go into the array. The rest won't go.
for ($i = 0; $i < mysql_num_rows($retid); $i++) {
QTY: <INPUT TYPE=text name="<? echo "qty".$i ?>" value="<? echo $quantity[$i] ?>" maxlength="3" size="3">
$index=0;
$tmp = "qty".$i ;
$quantity[] = $$tmp;
$index++;
}
I happened across the double $. This appears to act like dereferencing in C.
Without it, it just prints qty0, qty1 etc.
If in the same script I have this code, it will print the contents of the first two generated textboxs.
for ($i=0; $i <= $numrows+1;$i++) {
if (isset($inCart[$i])){
echo("<BR>" . $inCart[$i] . "<BR>");
echo ("1--->" . $quantity[0]);
echo ("2--->" . $quantity[1]);
}
}
However, if I put
echo ("all--->" . $quantity[$i]);
in place of the above singular echo, it only prints the last textboxs contents. Also, if I try to access these variables in another page, it can't find them. How do I pass an array in this way and get scalar contents in?
Is there a better way?(i'm sure!)
I hope this is legible enough to answer.
Thanks in advance.