-1

I have a query like SELECT * table from etc order by something LIMIT 10 but in the same time I also want to know the TOTAL row results in the table. Do I need to do another sql?

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

3 Answers3

0

If you want to see total rows return by the query you use mysqli_num_rows($sql)

$sql = mysqli_query($con,"SELECT * from etc order by something LIMIT 10");

$total_rows = @mysqli_num_rows($sql);

Edit :- If you want total of specifc coloumn say 'id' you can do like this :-

$total = 0;

while($result = mysqli_fetch_assoc($sql))
{

    $total = $total + $result['id'];

}

echo $total;
Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79
0

I had the same question, I had to do another sql... Here is what I used to count the numbers of users (userid>16 was due to sueprusers and deleted accounts):

SELECT
COUNT(*) AS "Number of users"
FROM 
Users
where  userid>16
user3223048
  • 163
  • 7
-2

If you are using mysql use this:

    $conn = mysql_connect('localhost', 'usename', 'password');
    if (!$conn) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db('database_name');


    mysql_query('SELECT * table from etc order by something LIMIT 10');
    echo mysql_affected_rows();
Karim Lahlou
  • 168
  • 5