Dus met je tabelvoorbeeld:
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
hoe de waarde 4 toe te kennen aan de kolom ticket_number van de gebruikersnaam SnowWhite, waarbij 4 de rangorde is van de rij in een gesorteerde selectie van de eerste rijen:
krijg eerst het gesorteerde resultaat:
$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;}
dit zou je iets moeten opleveren als:
[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]
foreach dan door je array
foreach ($array as $number => $row)
{if ($row[username] == $userinfo)
{$result = mysql_query('UPDATE table SET ticket_numer=' . ($number+1) . ' WHERE username=' . $userinfo);}}
de rij die overeenkomt met gebruikersnaam SnowWhite krijgt ($ number + 1) (3 + 1) als ticket_number