<?php $sql = "SELECT * FROM users ORDER BY active asc"; $result = $conn->query($sql); if($result->num_rows > 0) { while($row = $result->fetch_assoc()) { } } else { echo "Connection failed or no records found"; } ?>