1
burfodus
SELECT COUNT - sql wont work
  • 2009/3/28 2:03

  • burfodus

  • Just popping in

  • Posts: 94

  • Since: 2008/9/2 1


hi guys, I have tried on several occasions to use the SELECT COUNT function in my module.

this works (i use it further down on same page to form a select box)
$playerlist mysql_query("SELECT player_name FROM ".$xoopsDB->prefix('cuesportdraws_players')." ") or die('getting playerlist failed');


but this doesnt
$counttest mysql_query("SELECT COUNT player_name FROM ".$xoopsDB->prefix('cuesportdraws_players')." ") or die('getting playercount failed');


any help muchly appreciated.
im looking up sql commands to learn how to use them in xoops, if there is guidelines i need to follow or certain things i cant do id like to know them.

cheers
steve.
XOOPS Version - XOOPS 2.3.2
PHP Version - 5.2.6
MySQL Version - 5.0.67-community
Server API Version - apache2handler
OS Version - WINNT

2
ghia
Re: SELECT COUNT - sql wont work
  • 2009/3/28 9:23

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


It is select count(player_name) from ...
It might give you less results if there are some empty names, it is better to count on the id.
See also eg this FAQ and this SQL tutorial.

3
burfodus
Re: SELECT COUNT - sql wont work
  • 2009/3/28 15:13

  • burfodus

  • Just popping in

  • Posts: 94

  • Since: 2008/9/2 1


thanks ghia, I just resolved it in the last few hours, i must have tried 300+ cominations of syntax lol, but it wasnt working cos the number cant be interpreted i believe. this worked in the end.
$counttest mysql_query(" SELECT player_name FROM ".$xoopsDB->prefix('cuesportdraws_players')."") or die('count failed');
$test mysql_num_rows($counttest);


cheers
steve.
XOOPS Version - XOOPS 2.3.2
PHP Version - 5.2.6
MySQL Version - 5.0.67-community
Server API Version - apache2handler
OS Version - WINNT

4
ghia
Re: SELECT COUNT - sql wont work
  • 2009/3/28 17:54

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Quote:
but it wasnt working cos the number cant be interpreted i believe
I don't understand what you mean by that.

Your method will be very slow and intensive when there are a lot of users. To avoid!

5
iHackCode
Re: SELECT COUNT - sql wont work

some more useful info about count.

http://www.w3schools.com/SQL/sql_func_count.asp
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

6
burfodus
Re: SELECT COUNT - sql wont work
  • 2009/3/29 10:35

  • burfodus

  • Just popping in

  • Posts: 94

  • Since: 2008/9/2 1


from reading help files i could find on the net, it seemed the SELECT COUNT function returned the number in the form of a MySQL resource, and in php that is what would be displayed 'Resource ID #34' or whatever, the number was not relevent to anything.

I tried placing it in an array, but I would then just get 'array'.

this is why i asked the question here, cos if there was something i had to do to the resource to get it to work.

NB im not using it to count members, it will be for match numbers and to know which match number the winner goes to for my draw moduele. and it will only be in the backend when entering a draw, placing the winner goes to match number on submitting draw.

cheers
sb..

XOOPS Version - XOOPS 2.3.2
PHP Version - 5.2.6
MySQL Version - 5.0.67-community
Server API Version - apache2handler
OS Version - WINNT

7
ghia
Re: SELECT COUNT - sql wont work
  • 2009/3/29 11:16

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


I don't understand your problem. For an example see /include/findusers.php and function getCount.

Login

Who's Online

216 user(s) are online (127 user(s) are browsing Support Forums)


Members: 0


Guests: 216


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits