Reputation: 2403
How do you print the number of records in a mysql table?
Upvotes: 0
Views: 280
Reputation: 18109
Modified from PHP: mysql_result
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
if (!mysql_select_db('database_name')) {
die('Could not select database: ' . mysql_error());
}
$result = mysql_query('SELECT COUNT(*) FROM myTable');
if (!$result) {
die('Could not query:' . mysql_error());
}
$rowCount = mysql_result($result, 0); // get the count
echo $rowCount; // echo the count
mysql_close($link);
?>
Check out the PHP mysql functions if you're just getting started. If you're using any kind of framework, check out the database documentation for that framework.
Upvotes: 3
Reputation: 107706
Use this query to get the number of records in a table (e.g. named "tbl")
select count(*) as CountRecords from tbl
Upvotes: 3