Así que con tu ejemplo de tabla:
username ticket_number queue_time Doc 0 0 The 1st 3 not in sorted result Grumpy 0 0 Happy 0 0 Sleepy 1 111 The following are in sorted result Bashful 2 222 Sneezy 0 333 SnowWhite ??? 444 This is the current user (assign ???=4) Dopey 0 555 EvilQueen 0 666
cómo asignar el valor 4 a la columna ticket_number del nombre de usuario Blancanieves, siendo 4 el rango de la fila en una selección ordenada de las filas iniciales:
primero obtenga el resultado ordenado:
$result = mysql_query("SELECT * FROM table WHERE [here the condition for your sorted array]");
// don't forget to remove the []. they don't go there.
while ($row = mysql_fetch_assoc($result))
{$array[] = $row;}
esto debería darte algo como:
[0] [username] [Sleepy]
[ticket_number] [1]
[queue_time] [111]
[1] [username] [Bashful]
[ticket_number] [2]
[queue_time] [222]
[2] [username] [Sneezy]
[ticket_number] [0]
[queue_time] [333]
[3] [username] [SnowWhite]
[ticket_number] [NULL]
[queue_time] [444]
luego foreach a través de su matriz
foreach ($array as $number => $row)
{if ($row[username] == $userinfo)
{$result = mysql_query('UPDATE table SET ticket_numer=' . ($number+1) . ' WHERE username=' . $userinfo);}}
la fila correspondiente al nombre de usuario Blancanieves obtendrá ($número + 1) (3 + 1) como ticket_number