-3

I am getting some IDs from database and showing on page like this

2,
5,
9,
1,
7,

Anyone have idea how can i set and show like this in php

9,
7,
5,
2,
1,
Shaukat
  • 5
  • 2
  • How are you printing these? Add code. – Sougata Bose May 09 '15 at 06:45
  • i am using select query $sql = "SELECT * FROM status Where site='$site'"; $result = $conn->query($sql); while($row = $result->fetch_assoc()) { $id = $row['id']; } – Shaukat May 09 '15 at 06:48
  • It's called _sorting_. You can fetch rows from the database already sorted using an `ORDER BY` clause. `SELECT * FROM status WHERE site='$site' ORDER BY id DESC` – zaak May 09 '15 at 06:52
  • i am not getting table id – Shaukat May 09 '15 at 06:55
  • you can check this here i have a table monitors where have id,site_name and site_id and have some same value like as example.com id =3 , example.com id =1 , example.com id =8 – Shaukat May 09 '15 at 07:01

1 Answers1

0

Use rsort(). Try with -

while($row = $result->fetch_assoc()) {
    $ids[] = $row['id'];
}

$ids = rsort($ids);

rsort()

Sougata Bose
  • 30,169
  • 8
  • 42
  • 82