用php在mysql表中获取记录总数的最佳方法是什么? [英] Whats the best way to get total # of records in a mysql table with php?

查看:517
本文介绍了用php在mysql表中获取记录总数的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从大表中选择记录总数的最有效方法是什么?目前,我只是在做

Whats the most efficient way of selecting total number of records from a large table? Currently, Im simply doing

$result = mysql_query("SELECT id FROM table");
$total = mysql_num_rows($result)

有人告诉我,如果表中有很多记录,这不是非常有效或快速.

I was told this was not very efficient or fast, if you have a lot of records in the table.

推荐答案

您被正确告知. mysql可以为您完成这项工作,效率更高.

You were told correctly. mysql can do this count for you which is much more efficient.

$result = mysql_query( "select count(id) as num_rows from table" );
$row = mysql_fetch_object( $result );
$total = $row->num_rows;

这篇关于用php在mysql表中获取记录总数的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆