PDA

Click to See Complete Forum and Search --> : [RESOLVED] PHP Help please!


Pankirk
Aug 10th, 2008, 09:14 PM
So, I have a script that will allow users to post their account items onto a database where other users can post their items/ game currency onto the trade..... I'm sure it was hard to understand any of that, it's hard to explain. Anyway, the page where you put your items to trade is a page where i have a checkbox generated for each item you have. For example:

while($itemname = $getinvitemsres->fetch_assoc())
{
$id = $itemname['item_id'];
$user_ownid = $itemname['id'];

$getiteminfoagain = "select * from items where id = '".$id."'";
$getinfoagainres = $db->query($getiteminfoagain);
while($infoirem = $getinfoagainres->fetch_assoc())
{
$itemnamelol = $infoirem ['name'];
$itemidid = $infoirem ['id'];
$description = $infoirem['description'];
$rarity = $infoirem['rarity'];
$otheringo = $infoirem['other'];
$image = $infoirem['image'];

echo "<tr>
<td width='15%' align='center' valign='middle' style='border: 1px solid #CCCCCC;'><input type='checkbox' name='UNKNOWN' value='$itemnamelol'></td>
<td width='85%' valign='middle' style='border: 1px solid #CCCCCC;'><img src='/images/items/$image' width='85' height='85' alt='$description'>
$itemnamelol - <font color='green'>$rarity</font> <font color='orange'>$otheringo</font></td>
</tr>";
}
}
echo "</table><input type='submit' value='Create trade!' name='submit' /></form></center>";

that code gets all of the users items from their item table and puts them next to a check box. if you check the checkbox that item will be up for trading... ect. But, the problem i'm having is: since its unknown what the item is or what the value of the checkbox will be (its based on what the user has in their inventory) how can I get the value of the checkbox into an array (an array because it needs to be different for each of the items checked) and then I wull be able to use that array to continue on with the trading... If this doesnt make sense then please tell me so I can revise my post. Thank you so much in advance this helps a lot!

dclamp
Aug 10th, 2008, 09:18 PM
to array a checkbox do this:


<input type='checkbox' name='mycheckbox[]' value='peanuts'>


notice the name of the checkbox.

Pankirk
Aug 10th, 2008, 09:21 PM
Sorry, I don't think I get what your saying... Would that have a point though? If I have the checkbox name in an array can I then post it to the next page and will the values of the checkbox be in an array because the name is in an array? And if thats correct, then I don't think I know how to put the name of the checkbox into an array because thats not the way that i'm echoing the data?

dclamp
Aug 10th, 2008, 09:25 PM
that is how you do it. according to your code, it should look like this:


<input type='checkbox' name='itemname[]' value='$itemnamelol'>


HTML will automatically make it an array when posting it.

penagate
Aug 10th, 2008, 09:30 PM
If I have the checkbox name in an array can I then post it to the next page and will the values of the checkbox be in an array because the name is in an array?

If the field names end with [] then PHP will automatically create arrays when populating the $_POST variable.

dclamp
Aug 10th, 2008, 11:32 PM
If the field names end with [] then PHP will automatically create arrays when populating the $_POST variable.
which is what i said one post before you...

penagate
Aug 11th, 2008, 12:26 AM
Sort of, but it's nothing to do with HTML, or even HTTP. It's a PHP feature.

dclamp
Aug 11th, 2008, 12:27 AM
oh. i thought that the form did something before it sent it...

Pankirk
Aug 11th, 2008, 12:28 AM
Thank you very much for your replies guys! I will be back later if I have any more questions! Great help I really appreciate it!

dclamp
Aug 11th, 2008, 12:31 AM
well then please mark this thread as resolved as a courtesy to others.