Jadi dengan contoh tabel Anda:
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
cara menetapkan nilai 4 ke kolom ticket_number dari nama pengguna SnowWhite, 4 menjadi peringkat baris dalam pilihan yang diurutkan dari baris awal:
pertama dapatkan hasil yang diurutkan:
$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;}
ini akan memberi Anda sesuatu seperti:
[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]
lalu foreach melalui array Anda
foreach ($array as $number => $row)
{if ($row[username] == $userinfo)
{$result = mysql_query('UPDATE table SET ticket_numer=' . ($number+1) . ' WHERE username=' . $userinfo);}}
baris yang sesuai dengan nama pengguna SnowWhite akan mendapatkan ($number + 1) (3 + 1) sebagai ticket_number