Curious result with SELECT Count(*)

Post your questions and problem reports here

Moderator: kfury77

Forum rules
Please try to follow these guidelines. This will help to receive faster and more accurate response.
  • Check the Support section of the corresponding product first. Chances are you will find your answer there;
  • Do not create new topics for already reported problems. Add your comments to the existing topics instead;
  • Create separate topic for each problem request. Do NOT post a number of non-related problem reports in a single topic;
  • Give your topic a meaningful title. Titles such as "A question," "Bug report" and "Help!" provide others no clue what your message is about;
  • Include the version number of the software you are using;
  • This is not an official customer support helpdesk. If you need a prompt and official response, please contact our support team directly instead. It may take a while until you receive a reply in the forum;
Post Reply
qbuster
Posts: 9
Joined: Wed Nov 07, 2007 2:50 pm
Location: Alrewas, Staffs UK

Curious result with SELECT Count(*)

Post by qbuster »

When I enter SELECT COUNT(*) FROM sowparas into the Rapid PHP Sql Query browser (or indeed the MySql Query Browser) I get a correct answer of 36 (rows).

However, in the following php script the query always returns 1 instead of the correct 36. Can anyone shed any light on this?

$query = 'SELECT COUNT(*) fFROM sowparas" ;

$result = @mysqli_query ($dbc, $query);

$rows = number_format($result,2);

echo "row count=$rows" ."\n";

I'm mystified....!

Cheers

Will
User avatar
chrisjlocke
Top Contributor
Posts: 995
Joined: Mon Aug 01, 2005 4:12 pm
Location: Essex, UK
Contact:

Post by chrisjlocke »

Might be a typo from you typing, but the $query like has an opening single quote, but a closing double quote.

Does the number_format function work correctly in other scripts?
Looking through some of my PHP code, I use the mysql_num_rows($result) function.
qbuster
Posts: 9
Joined: Wed Nov 07, 2007 2:50 pm
Location: Alrewas, Staffs UK

Post by qbuster »

chrisjlocke wrote:Might be a typo from you typing, but the $query like has an opening single quote, but a closing double quote.

Does the number_format function work correctly in other scripts?
Looking through some of my PHP code, I use the mysql_num_rows($result) function.
Sorry about those typos...don't know how they slipped in. But, anyway, I've just checked again (making sure there are no typos - see code below): and I still get the same result. A count of 36 in Mysqlbrowser and 1 in a php script.

I use the mysql_num_rows as well but I just wondered why SELECT COUNT(*) works in some scenarios and not others.

Thanks for your reply..

Cheers


Will
User avatar
chrisjlocke
Top Contributor
Posts: 995
Joined: Mon Aug 01, 2005 4:12 pm
Location: Essex, UK
Contact:

Post by chrisjlocke »

Its not the select count (*) thats different, but the resultant code. Im not too hot on php, but '$rows = number_format($result,2); ' doesn't look valid to me - $result is an array of the result from the query. You're asking php to convert this into a 'number_format'. You're probably getting 1 which means 'success'.

If mysql_num_rows works, then simply use that.
qbuster
Posts: 9
Joined: Wed Nov 07, 2007 2:50 pm
Location: Alrewas, Staffs UK

Post by qbuster »

chrisjlocke wrote:Its not the select count (*) thats different, but the resultant code. Im not too hot on php, but '$rows = number_format($result,2); ' doesn't look valid to me - $result is an array of the result from the query. You're asking php to convert this into a 'number_format'. You're probably getting 1 which means 'success'.
No that's not the problem. number_format() converts a numeric value into a string for presentation purposes.

Cheers


Will
Post Reply