• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

code to display number of`SQL records

ozefrog

Active Member
code to display number of SQL records

could some1 please tell me the code to make php pull out the number of sql records in a whole database

and the number of sql records in a whole table



thanx
 
ok i have used this :

<html>
<body>
<?php
include("dbconfig.php");
$db = mysql_connect($serverAddress,$databaseName,$serverPass)or die("Couldn't make connection.");
mysql_select_db($databaseName,$db)or die("Couldn't select database");
$result = mysql_query("select count(*) from joke5",$db);

printf($result);

?>
</body>
</html>

and it wont retrieve it, it just comes up with Resource id #2 or something
 
Replace:

$result = mysql_query("select count(*) from joke5",$db);

... with ...

list ($joke5count) = mysql_fetch_row(mysql_query("select count(*) as rscount from joke5"));
echo $joke5count;

Also, if the table (joke5) is pretty big then replace count(*) with count([FieldName]) where [FieldName] is any primary key or index field (like: RecordID etc).
 
Actually... Here's how you efficiently return a row count...

PHP:
$strQuery = mysql_db_query("SELECT count(*) FROM table", $db);
$intCount = mysql_result($strQuery, 0);
print $intCount;
 
Back
Top