Så med ditt tabellexempel:
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
hur man tilldelar värdet 4 till kolumnen ticket_number för användarnamnet SnowWhite, där 4 är rangordningen för raden i ett sorterat urval av de initiala raderna:
först få det sorterade resultatet:
$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;}
detta borde ge dig något i stil med:
[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]
gå sedan igenom din array
foreach ($array as $number => $row)
{if ($row[username] == $userinfo)
{$result = mysql_query('UPDATE table SET ticket_numer=' . ($number+1) . ' WHERE username=' . $userinfo);}}
raden som motsvarar användarnamnet SnowWhite får ($number + 1) (3 + 1) som ticket_number