Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2006-10-13, 01:51 PM
Junior Member
 
Join Date: Oct 2006
Posts: 1
CGRRay is on a distinguished road
Default Problem counting records

I'm trying to count members in chapters from the table cl_member and order them by their chapter. This is the query I'm trying to use. For some reason it works in MySQL Query Browser but I get this error message when I run it using phpMyAdmin.


#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT COUNT(member_id)
FROM cl_member
WHERE cl_member.chapte


Here's the query:



SELECT cl_chapter.title, (
SELECT COUNT( member_id )
FROM cl_member
WHERE cl_member.chapter_id = cl_chapter.chapter_id
AND cl_member.date_expires >1146441599
) AS members_as_of_Mar31, (
SELECT COUNT( member_id )
FROM cl_member
WHERE cl_member.chapter_id = cl_chapter.chapter_id
AND cl_member.date_expires
BETWEEN 1146441600
AND 1162339199
) AS expired_after_Mar31, (
SELECT COUNT( member_id )
FROM cl_member
WHERE cl_member.chapter_id = cl_chapter.chapter_id
AND cl_member.date_joined
BETWEEN 1146441600
AND 1162339199
) AS joined_after_Mar31, (
SELECT COUNT( member_id )
FROM cl_member
WHERE cl_member.chapter_id = cl_chapter.chapter_id
AND cl_member.date_renewed
BETWEEN 1146441600
AND 1162339199
) AS renewed_after_Mar31
FROM cl_chapter
ORDER BY cl_chapter.title

Any help would be greatly appreciated.
Ray
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2006-10-13, 05:38 PM
Senior Member
 
Join Date: Jul 2006
Location: Prague, Czech Republic
Posts: 193
vladimir_cz is on a distinguished road
Send a message via ICQ to vladimir_cz Send a message via MSN to vladimir_cz Send a message via Yahoo to vladimir_cz Send a message via Skype™ to vladimir_cz
Default

Hi!

Please read documentation for MySQL selects (http://dev.mysql.com/doc/refman/4.1/en/select.html)
did you see any complex selects like you wrote?
__________________
Thank you. Vladimir, Czech Republic.
http://www.smartwebco.com/
I'm looking for job.
Reply With Quote
  #3 (permalink)  
Old 2006-10-13, 05:40 PM
Senior Member
 
Join Date: Jul 2006
Location: Prague, Czech Republic
Posts: 193
vladimir_cz is on a distinguished road
Send a message via ICQ to vladimir_cz Send a message via MSN to vladimir_cz Send a message via Yahoo to vladimir_cz Send a message via Skype™ to vladimir_cz
Default

just for make your life simle, try to use grouping, something like this

select year(join_date),month(join_date),count(*) from table group by year(join_date),month(join_date)
__________________
Thank you. Vladimir, Czech Republic.
http://www.smartwebco.com/
I'm looking for job.
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 11:22 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.