Array Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Snobbery08
Forum Newbie
Posts: 13
Joined: Sun Jan 06, 2008 10:45 am

Array Help

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Array Help

Post by Christopher »

I am confused too? Do you want a <select> ? Or radio buttons?
(#10850)
Snobbery08
Forum Newbie
Posts: 13
Joined: Sun Jan 06, 2008 10:45 am

Re: Array Help

Post 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 ?
Post Reply