Results 1 to 10 of 10

Thread: [RESOLVED] PHP Help please!

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    8

    [RESOLVED] PHP Help please!

    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:

    Code:
    				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!
    Last edited by Pankirk; Aug 11th, 2008 at 01:02 AM.

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Help please!

    to array a checkbox do this:

    HTML Code:
    <input type='checkbox' name='mycheckbox[]' value='peanuts'>
    notice the name of the checkbox.
    My usual boring signature: Something

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    8

    Re: PHP Help please!

    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?

  4. #4
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Help please!

    that is how you do it. according to your code, it should look like this:

    Code:
    <input type='checkbox' name='itemname[]' value='$itemnamelol'>
    HTML will automatically make it an array when posting it.
    My usual boring signature: Something

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP Help please!

    Quote Originally Posted by Pankirk
    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.

  6. #6
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Help please!

    Quote Originally Posted by penagate
    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...
    My usual boring signature: Something

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP Help please!

    Sort of, but it's nothing to do with HTML, or even HTTP. It's a PHP feature.

  8. #8
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Help please!

    oh. i thought that the form did something before it sent it...
    My usual boring signature: Something

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    8

    Re: PHP Help please!

    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!

  10. #10
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP Help please!

    well then please mark this thread as resolved as a courtesy to others.
    My usual boring signature: Something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width