Jump to content


Photo

Selecting multiple checkboxes


  • Please log in to reply
3 replies to this topic

#1 Andrew R

Andrew R
  • Members
  • PipPipPip
  • Advanced Member
  • 158 posts
  • LocationIreland

Posted 10 October 2006 - 06:04 PM

Hi

I am having trouble writing a script that will select multiple flight ids (from a checkbox) and process them into another page via the $_POST function

So for example I select flight id (RFS1869 and RFS5697 from the checkbox) and it will display information about these two results in another page.

Can anybody point me in to any tutorials or anything that will help with learn how to do this.

Cheers


#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 10 October 2006 - 06:11 PM

in your form:
<form action='target.php' method='post'>
   <input type = 'checkbox' name = 'somevar[]' value = 'rfs1869'> rfs1869 <br>
   <input type = 'checkbox' name = 'somevar[]' value = 'rfs5697'> rfs5697 <br>
   <input type = 'submit' value='submit'>
</form>

target.php
$somevar = $_POST['somevar'];

// example
foreach ($somevar as $val) {
   echo "$val <br>"; // echo out each element in $somevar array
}

//another example
echo $somevar[0]; //echos first checkbox that was checked
echo $somevar[1]; //echos 2nd checkbox that was checked

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 Andrew R

Andrew R
  • Members
  • PipPipPip
  • Advanced Member
  • 158 posts
  • LocationIreland

Posted 10 October 2006 - 06:15 PM

Cheers for that, although the only problem being the values for flight_id are being pulled out from the database and then displayed in a table.
<?php echo $row_flights['flight_id']; ?>


#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 10 October 2006 - 06:21 PM

If you want to get the values for the checkboxes from the database, then you can do it like this:
while($row = mysql_fetch_assoc($query_result)
{
	echo "\t<label><input type='checkbox' name='flight_ids[]' value='{$row['value']}' /> {$row['user_readable_name']}</label>\n";
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users