PDA

View Full Version : SQL Count error


jasharen
07-08-2007, 06:12 PM
I am having a problem using a datamanager to return a record count for me. The sql server query returns 41 records and the datamanager entry returns 46.


Datamanager SQL statement:
SELECT COUNT(*) as count FROM " . TABLE_PREFIX . "companies"

$result = $db->query_read($dataman->fetch_count());
$list = mysql_fetch_object($result);
$totalcompanies = $list->count;


Any idea why this would be happening? Its driving me nuts lol


$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'mydb';
mysql_select_db($dbname, $conn);
$result = mysql_query("select count(*) as count from companies");
$list = mysql_fetch_object($result);
$totalcompanies = $list->count;
echo $totalcompanies;
mysql_close($con);


When the above code is run it returns 41...

nm /sigh

My own stupidity.

analog2112
07-09-2007, 01:28 AM
Are you using MySQL 5? I saw this same sort of thing when I did a "select count (*)", just for kicks try replacing the wildcard with a column name and see what you get "select count (some_column_in_companies)"

jasharen
09-12-2007, 03:41 AM
In this case I was connected to two different databases. Almost carbon copies of each other, but one was hitting the *live* database and the other was hitting the development db.

All I can say is I was tired at the time lol