Jump to content

Checkbox on search form is there another way?


ijyoung

Recommended Posts

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?

 

 

Archived

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

×
×
  • Create New...

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.