获取MySQL数据库中的项目数
我正在使用 php 为我的 iPhone 应用程序创建一个高分数据库。但是它只会显示 100 个高分(我设置的)。如何更改它以获取数据库中所有行的计数?
这是我的代码的一部分:
$table = "highscores";
// Initialization
$conn = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);
// Error checking
if(!$conn) {
die('Could not connect ' . mysql_error());
}
$type = isset($_GET['type']) ? $_GET['type'] : "global";
$offset = isset($_GET['offset']) ? $_GET['offset'] : "0";
$count = isset($_GET['count']) ? $_GET['count'] : "100";
$sort = isset($_GET['sort']) ? $_GET['sort'] : "score DESC";
I am using php to create a highscore database for my iPhone Application. However it will only show 100 highscores (that I set). How can I change this to get the count of all of the rows in the database?
Here is part of my code:
$table = "highscores";
// Initialization
$conn = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);
// Error checking
if(!$conn) {
die('Could not connect ' . mysql_error());
}
$type = isset($_GET['type']) ? $_GET['type'] : "global";
$offset = isset($_GET['offset']) ? $_GET['offset'] : "0";
$count = isset($_GET['count']) ? $_GET['count'] : "100";
$sort = isset($_GET['sort']) ? $_GET['sort'] : "score DESC";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要获取表中的记录数,您可以尝试以下代码:
To get the number of records from a table, you can try following code:
SELECT COUNT(*) FROM highscores
将为您提供 highscore 表中的行数。但是,如果您想要这样做,您也可以通过从查询中消除LIMIT
子句来获取所有行。 SQL 默认为您提供所有匹配的行。SELECT COUNT(*) FROM highscores
will give you the number of rows in the highscores table. But you would also get all the rows, if that's what you want to do, by eliminating theLIMIT
clause from your query. SQL defaults to giving you all of the rows that match.这是一篇关于使用 PHP 获取 MySQL 表大小
希望有帮助。
Here's a good article for Getting MySQL Table Size with PHP
Hope that helps.