PDA

View Full Version : Form Help.



Lilian
11-05-2007, 07:17 PM
Ok I neeed a little help. I need to change this drop down menu to check buttons but need a little help.


<select name="p_id">
<?php
$SQL = "SELECT * from options";
$result = mysql_query( $SQL );
while( $row = mysql_fetch_array( $result ) ) {
$id = $row["ID"];
$name = $row["NAME"];
?>
<option value="<?php echo $id; ?>"> <?php echo $name; ?></option>
<?php } ?>
</select>

How could I change that so that the options show up in a checkbox form method instead of a drop down menu.

+REP to anyone who can help.

QuickScriptz
11-05-2007, 07:19 PM
Use this for each of your checkboxes:


<input type="checkbox" value="<?php echo $id; ?>" /><?php echo $name; ?>

Lilian
11-05-2007, 07:21 PM
Thanks got it.

Epanel
18-05-2007, 09:13 AM
Ok Say I wanted That But They Cant TICK all at once? how..

Firehorse
18-05-2007, 02:59 PM
Ok Say I wanted That But They Cant TICK all at once? how..

What you need are radio buttons if you want them only to check one, Check boxes are simply boxes that you can check where as radio buttons you can only select one option.

Does this help?

Romanity
18-05-2007, 07:24 PM
If you wanted them to be able to select more than one option...



<?
echo("<form>");
$SQL = "SELECT * from options";
$result = mysql_query( $SQL );
while( $row = mysql_fetch_array( $result ) ) {
$id = $row["ID"];
$name = $row["NAME"];
echo("<input type='checkbox' name='box[]' value='$id'> $name");
}
("</form>");
?>


Then when submitted...


$array = $_POST[box];
foreach($array as $val){ //$val is the ID of each row
//Whatever you want to do with each of the selected values
}

Want to hide these adverts? Register an account for free!