简体   繁体   中英

How to get count of Number of rows returned?

I have this query which I am getting the count of the number of songs clicked is it possible to get the number of rows returned? as my host doesn't allow query that take a long time so I was thinking to get the number of rows then run the query again and offset it to get the next 50 and so on

SELECT mv.id, mv.songname, mv.slug, (SELECT Count(*) FROM clickedsongname WHERE clickedsongname.songid = mv.id) Count FROM videoname mv;

I've tried doing this to get the count:

SELECT count(*) mv.id, mv.songname, mv.slug, (SELECT Count(*) FROM clickedsongname WHERE clickedsongname.songid = mv.id) Count FROM videoname mv;

and

SELECT count(*) mv.id, mv.songname, mv.slug, (SELECT Count(*) FROM clickedsongname WHERE clickedsongname.songid = mv.id) Count FROM videoname mv as overallcount

You can use some built in PHP MySQLi functions.

#define the connection
$con = mysqli_connect("ip","user","pass","dbname");

#define the query
$query = '(query that gets rows)';

#run the query
$result = mysqli_query($con, $query) or die(mysql_error());

#Get the row count
$rows = mysqli_num_rows($result);

print_r($rows);

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM