i have a form field that lists the order of a few different items by priority. when you type in a higher number into the field and submit i want that item to be moved up the list and all the numbers lower than it updated by one(ala netflix). here is the code i'm trying:
if ($submitslot) {
mysql_connect("","","");
mysql_select_db("");
$query="SELECT * FROM info";
$result=mysql_query($query);
$num=mysql_numrows($result);
echo "$num----number of rows<br>";
echo "$ud_tempslot----this is the value coming from the form<br>";
$query2="SELECT directorslot FROM info ORDER BY directorslot ASC";
$result2=mysql_query($query2);
$i=$ud_tempslot-1;
while ($i < $num) {
$test=mysql_result($result2,$i,"directorslot");
$test2=$test+1;
echo "$test goes to $test2<br>";
$query3="UPDATE info SET directorslot='$test2' WHERE directorslot='$test'";
mysql_query($query3);
echo "$query3<BR>";
$i++;
}
mysql_close();
}
this is the output:
4----number of rows
1----moved to this slot
1 goes to 2
UPDATE info SET directorslot='2' WHERE directorslot='1'
2 goes to 3
UPDATE info SET directorslot='3' WHERE directorslot='2'
3 goes to 4
UPDATE info SET directorslot='4' WHERE directorslot='3'
4 goes to 5
UPDATE info SET directorslot='5' WHERE directorslot='4'
this is when i submit #2 to go into #1, which seems fine. but then the actual values for directorslot for all the the items ends up being 5. any idea why this is happening?