ijyoung Posted October 6, 2008 Share Posted October 6, 2008 Using checboxes to select a choice on a form generated from a search from Database. Form code <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <? if ($row['ood_id']) { $name= $row['ood']; $duty='Race Officer'; ?> <table width="70%" align="center" bgcolor="red"> <tr><td width="20%">Date</td><td width="20%">Event</td><td width="20%">Name</td><td width="20%">Duty</td><td width="20%"><input type="radio" name="switch" /></td></tr> <tr> <td><?php echo $row['dr']?> <input type="hidden" name="id" value="<?=$row['ood_id']?>"/> <input type="hidden" name="date" value="<?=$row['date']?>"/></td> <td><? echo $row['event']?></td> <td><? echo $name?><input type="hidden" name="name" size = "25" value="<?php echo $name ?>"/></td> <td><? echo $duty?><input type="hidden" name="duty" size = "" value="<?php echo $duty ?>"/></td> </tr> <tr><td colspan="5"><hr /></td></tr> </table> <? } if ($row['s_id']) { $name2= $row['safety']; $duty2='Safety'; ?> <table width="70%" align="center" bgcolor="red"> <tr><td width="20%">Date</td><td width="20%">Event</td><td width="20%">Name</td><td width="20%">Duty</td><td width="20%"><input type="radio" name="switch-s" /></td></tr> <tr> <td><? echo $row['dr']?></td> <td><? echo $row['event']?></td> <td><? echo $name2?></td> <td><? echo $duty2?></td> </tr> <tr><td colspan="5"><hr /></td></tr> </table> //etc </form> <? } form is handled by if (!empty($_POST['switch'])) { $name = escape_data($_POST['name-1']); $dat = escape_data($_POST['date-1']); }else{ $name= FALSE; $dat = FALSE; } if (!empty($_POST['switch2'])) { $name2 = escape_data($_POST['name-2']); $dat2 = escape_data($_POST['date-2']); }else{ $name2= FALSE; $dat2 = FALSE; } //etc Of course, when the results are generated there are more than one for each selection eg Checkbox "switch" would give Date Event Name Duty Today Something Ian Young Race Officer Date Event Name Duty Tomorrow Something2 Joe Bloogs Race Officer and so on. Problem as I see it is that both these results are identical according to the if statement, but I selected Joe Bloggs. So how do I use a checkbox (or anything else for that matter) that will just select Joe Bloogs? Link to comment https://forums.phpfreaks.com/topic/127204-checkbox-on-search-form-is-there-another-way/ Share on other sites More sharing options...
ijyoung Posted October 7, 2008 Author Share Posted October 7, 2008 Sorted. Used an array with switch and then called the value that I needed using a foreach loop. see:http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/Q_23276510.html Cheers Ian Link to comment https://forums.phpfreaks.com/topic/127204-checkbox-on-search-form-is-there-another-way/#findComment-658981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.