Ok, here's a fun one. My client asks for priority selector boxes. I make boxes that submit the item's selected priority onChange. No problem. But "No" they say, "What we really wanted was numbering boxes, that are auto-popped by how many total rows there are, and no two records can have the same "priority" value." With me so far?
I had to laugh, but basically, I'm not sure how to make sure the priority fields stays unique. So if we have:
clientid | fName | lName | priority
00001 | Joe | Smith | 1
00002 | Jane | Doe | 2
00003 | Jack | Sprat | 3
And I want to change Jane Doe to priority 1, how do I make sure that Joe Smith trades priorities with her? Oh, and if with the current set up, Jane Doe of priority 2 gets deleted, I need to make sure Jack is number 2 now. And if there are places 4, 5, 6, they all need to increment up one.
Here's what I used for my original priority selector:
form.php
<td align="center"><select name="servicePriority" onChange="selectPriority(this)">
<?php
for ($p = 1; $p <= 3; $p++) {
if ($p == $a_row['servicePriority']) {
$prioritySelected[$p] = "selected=\"selected\"";
} else {
$prioritySelected[$p] = "";
}
?>
<option <? print $prioritySelected[$p]; ?> value="actions/updateServiceAction.php?action=priority&priority=<? print $p; ?>&serviceid=<? print $a_row['serviceid']; ?>"><? print $p; ?></option>
<?
}
?>
</select></td>
selectPriority() just calls what I call an action page which has this on it:
action.php
$query = "UPDATE services SET servicePriority='$priority'
WHERE serviceid='$serviceid'";
if ( ! mysql_query( $query, $link ) ) {
print mysql_error();
return false;
}