Compare values of drop downs within a category
Hi all, I got a question concerning form validation (drop down). I am about to write a script for the election of the management comittee of a club. Thereby, I have different categories and within this categories different persons nominated for a specific position. While the election is running, the members can either elect the nominated persons or exchange them by another member. Therefore, I use drop downs. Now, the requirement is that for all the drop downs which are displayed in one and the same category, a person can only be selected once. E.g. a person who was selected in drop down 1 of category A, cannot be as well selected in drop down 2 of category A. Since there is a variable number of drop downs per category, once submitted, I have to process the data in a foreach. My problem is, by processing it in a foreach, how can I compare the different drop downs of one and the same category and output an error if a person appears in the two or several drop downs per category. Here is what I do right now. The current code works very well, however, I simply cannot compare the different values of the drop downs per category.
I am really at a loss because I should implement this check till Tuesday and I simply don’t know how. I already had a sleepless night, I guess another one will follow. I spent hours on end in forums but couldn’t find a post with the same or similar issue.
Thanks a lot for your tipps
Drop down creation:
PHP Code:
$count=1;
$get_categories= mysql_query("SELECT * FROM $tab_gvcategories WHERE status='1' and election_id='$_POST[electionid]'");
while ($categories = mysql_fetch_array($get_categories))
{ $count1=$count++;
echo"<tr>
<td width=\"100%\" colspan=\"2\" height=\"19\"><b>$categories[description]</b></td>
</tr>
<tr>
<td width=\"99%\" colspan=\"2\" bgcolor=\"#FFFFFF\"><img border=\"0\" src=\"http://belpers.ch/home/design/spacer.gif\" width=\"1\" height=\"1\"></td>
</tr>
<tr>
<td width=\"100%\" colspan=\"2\" height=\"19\"></td>
</tr>";
$get_candidates= mysql_query("SELECT * FROM $tab_gvcandidates WHERE status='1' AND category='$categories[id]' ORDER BY id asc");
$avail_candidates_num_rows = mysql_num_rows($get_candidates);
while ($candidates = mysql_fetch_array($get_candidates))
{
echo"<tr>
<td width=\"30%\" height=\"19\"><INPUT TYPE=\"hidden\" NAME=\"position[]\" VALUE=\"$candidates[position]\">$candidates[position]:</td>
<td width=\"70%\" height=\"19\"><select name=\"candidate[]\">";
$sqlbefehl= "Select * FROM $tab_user Where mitgliedschaft_type='1' and user_id<>'66' and user_id<>'1' order by nickname ASC";
$getothers = mysql_query($sqlbefehl, $serverid);
echo mysql_error();
while ( $others = mysql_fetch_array($getothers)) {
if($others[user_id] == $candidates[user_id]){$selected="selected";} else {$selected="";}
echo"<option $selected value=\"$candidates[position]_$others[user_id]\">$others[nickname]</option>";}
echo"</select>
</td>
</tr>
"; }
echo"<tr>
<td width=\"100%\" colspan=\"5\" height=\"40\"></td>
</tr>";}
Processing after submit:
PHP Code:
$chbxarray=$_POST[candidate];
foreach ($chbxarray as $v) {
$array = explode("_",$v);
$getit_poll8 = mysql_query("Select Count(*) as TOTAL From bepoll_gvdata Where amt='$array[0]' and auswahl='$array[1]'");
$vorstandswahl_exists = mysql_fetch_array ($getit_poll8);
if ($vorstandswahl_exists[TOTAL] == 0 ){
$sqlbefehl = "INSERT INTO bepoll_gvdata
(amt,auswahl,votes)
VALUES ('$array[0]','$array[1]','1')";
if (!$ergebnis = mysql_query($sqlbefehl, $serverid))
echo mysql_error($serverid);
$new_id = mysql_insert_id($serverid);}
else {
$sqlbefehl = "update bepoll_gvdata set votes=votes+1 where amt='$array[0]' and auswahl='$array[1]'";
mysql_query($sqlbefehl, $serverid);}
}
View full post on Webmaster-Talk.com
category, Compare, downs, Drop, Values, within