Borja
Borja

Reputation: 3551

How count many rows returned in select of Mysql?

can you suggest me how count rows returned in select of Mysql ?

$n_quakes = "SELECT COUNT(*) 
             FROM earthquakes 
             WHERE milliseconds >= 1000 
               AND milliseconds <= 2000 
               AND magnitude >= 4 
               AND magnitude <= 8 
               AND ipocentro >= 50 
               AND ipocentro <= 800 
               AND latitude >= 40 
               AND latitude <= 50 
               AND longitude >= 30 
               AND longitude <= 70";

In this way i'll know number of rows ?

In my code doesn't work but i don't no if this is error or is in other place of code.

Thanks for help and sorry for my english

Upvotes: 0

Views: 71

Answers (2)

sam
sam

Reputation: 167

try this code, where mysqli_num_rows returns number of rows and $con is database connection variable

$n_quakes = mysqli_num_rows(mysqli_query($con, "SELECT id FROM earthquakes WHERE milliseconds >= 1000 AND milliseconds <= 2000 AND magnitude >= 4 AND magnitude <= 8 AND ipocentro >= 50 AND ipocentro <= 800 AND latitude >= 40 AND latitude <= 50 AND longitude >= 30 AND longitude <= 70"));

Upvotes: 0

Roshni hegde
Roshni hegde

Reputation: 415

Try this using between

$count = mysqli_fetch_array(mysqli_query($coni, "SELECT COUNT(*) as totalCount
             FROM earthquakes 
             WHERE (milliseconds between 1000 and 2000) and (magnitude between 4 and 8) AND (ipocentro between 50 and 800) AND (latitude between 40 and 50) and (longitude between 30 and 70)"));

$actualCount =  $count['totalCount'];

Upvotes: 2

Related Questions