Register FAQ/Rules Forum Spy Search Today's Posts Mark Forums Read

Welcome to the Mac Forums forums. Please read the FAQ if you have questions. Register to participate.

 
Go Back   Mac Forums > Special Interests > Web Design and Development
TouchArcade.com - iPhone Game Reviews and News

Reply
 
Thread Tools Search this Thread  
Old Aug 5, 2008, 09:30 AM   #1
vendettabass
macrumors 6502a
 
vendettabass's Avatar
 
Join Date: Jul 2006
Location: Manchester, UK
Send a message via Skype™ to vendettabass
PHP Checkboxes

hey guys, I've scoured the internet and found no resolution to my problem :-(.

Basically I'm trying to add members (read from a database) to an event. I'm using checkboxes for the admin to select multiple users to add to the event. (Note: the <form> is further up the code).

while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo "<tr class='even'><td>".$row[name]."</td><td><input name='members[]' value='".$row[id]."' type='checkbox' /></td>";
}
echo "</table>";
echo "<p><input type='submit' value='Complete Event' id='submit' /></p>";
echo "</form>";


The $row[id] are numbers, and what I need are these numbers in an array on the next page so I can use them. I just can't figure out how to get these numbers.

Any idea what syntax I'll need to obtain each item from the array?

thanks a lot
vendettabass is offline   Reply With Quote
Old Aug 5, 2008, 09:43 AM   #2
SrWebDeveloper
macrumors 65816
 
Join Date: Dec 2007
Location: Falls Church, Va.
When the form is submitted, if you used post method:

$_POST['members']

If get method:

$_GET['members']

Each will be an array, so to iterate through, one of million ways, but easy:

PHP Code:
foreach ($_POST['members'] as $MemberID) {
echo 
"A user with ID number $MemberID was selected<br />";

Good job using [] on the end of the name field in your input tag for the checkboxes. Many people forget to do that in PHP - doing so easily creates an array in your $_POST or $_GET global variable which PHP creates for you. Well done!

-jim
__________________
Jim, Sr. Web Developer
If you ever want to know who you true friends are, ask them to either paint or move furniture.
SrWebDeveloper is offline   Reply With Quote

Reply

Mac Forums > Special Interests > Web Design and Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 07:43 PM.

Mac News | Mac Rumors | iPhone Game Reviews | iPhone Apps

Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 2002-2009, MacRumors.com, LLC