Jump to content

Archived

This topic is now archived and is closed to further replies.

Andrew R

Selecting multiple checkboxes

Recommended Posts

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

Share this post


Link to post
Share on other sites
in your form:
[code]
<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>
[/code]

target.php
[code]
$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
[/code]

Share this post


Link to post
Share on other sites
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. [code]<?php echo $row_flights['flight_id']; ?>[/code]

Share this post


Link to post
Share on other sites
If you want to get the values for the checkboxes from the database, then you can do it like this: [code]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";
}[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.