Page 1 of 1

Array Help

Posted: Fri Feb 15, 2008 6:18 pm
by Snobbery08
Not sure if I am doing this correctly so was hoping some one could tell me if i am going in the correct direction with this...

I have tried to create an array in a form to process on the next page but am getting problems with it.

I have two entires the user has to do which is "select the items" and set the "quantity" of those items..

So lets say:

ItemID |Quantity
---3------|------4
---2------|------2
---7------|------1


These are the items the user picked and the corresponding quantities. Now i have applied that to my form below:

Code: Select all

<?php
$Array = 0;
            While($row = mysql_fetch_assoc($GetItems)){
            $ItemID = $row['ItemID'];
            $Quantity = $row['Quantity'];
            $Get = mysql_query("SELECT Name,Type FROM item WHERE ItemID='$ItemID' AND Trade='1'")
                Or die(mysql_error());
            $row = mysql_fetch_assoc($Get);
            $Name = $row['Name'];
            $Type = $row['Type'];
            $Array++;
            ?>
            <tr>
            <td width="200" align="center" class="blackBold"><?=$Name?></td>
            <td width="200" align="center" class="blackBold"><?=$Quantity?></td>
            <td width="200" align="center" class="blackBold"><input type="text" size="16" name="Quantity[<?=$Array?>]" value=""></td>
            <td width="200" align="center" class="blackBold"><input type="checkbox" name="Checkbox[<?=$Array?>]" value="<?=$ItemID?>"></td>
            </tr>
            <?php
                }
?>
This part is fine but the below part is my process page which i need help with i get an undefined error... to do with $ItemID (you can tell im a noob with arrays).
Notice: Undefined variable: ItemID in C:\xampp\htdocs\transferprocess.php on line 5
This is my process:

Code: Select all

 
<?php
If(isset($_POST['Button1']) && isset($_POST['Checkbox']) && isset($_POST['Quantity'])){
for($Array = 0; $Array < count($ItemID); $Array++){
if($Quantity[$Array]){
echo $ItemID[$Array] . " - " . $Quantity[$Array];
}else{
echo "Please insert a quantity for item id " . $item[$a];
    } 
} 
 
}
 
?>

It's so confusing! Not sure if I am going in the right direction? Hope you can help me here I ain't totally understood array's greatly.

Re: Array Help

Posted: Fri Feb 15, 2008 8:02 pm
by Christopher
I am confused too? Do you want a <select> ? Or radio buttons?

Re: Array Help

Posted: Fri Feb 15, 2008 8:09 pm
by Snobbery08
Well radio buttons only allow you to select one option. Multiple choices are needed to be allowed here. Which is why I used check box's .Im assuming that was what you were asking ?