简体   繁体   English

如何获取返回的行数?

[英]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因为我的主机不允许需要很长时间的查询所以我想获取行数然后再次运行查询并偏移它以获得下一个 50 等等

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.您可以使用一些内置的 PHP MySQLi 功能。

#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!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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