Counting rows in table

Here is my flow can somebody help me with syntax.

COUNT * FROM $table with class = $classid
IF COUNT < $maxsize {do this}
ELSE {do that}
LVL 1
livegirlloveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Diablo84Commented:
I think you are looking for something like this:

SELECT COUNT(*) as mycount FROM $table WHERE class = '$classid'

mysql eg:

$query = mysql_query("SELECT COUNT(*) as mycount FROM $table WHERE class = '$classid'") or die(mysql_error());

if (mysql_result($query,0,'mycount') < $maxsize) {
 //do this
}
else {
 //do that
}

You might just count a specific column rather then all (*) to speed up the query.

Diablo84

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
livegirlloveAuthor Commented:
That was fast ;-)

SELECT COUNT(class) as mycount FROM $table WHERE class = '$classid'") or die(mysql_error());
since I just need to know how many people are signed up for that class...

if (mysql_result($query,0,'mycount') < $maxsize) {
What is the 0 after the $query?

thanks!!
Diablo84Commented:
:)

0 corresponds to the row number, since the query will only return one row you just need to reference row 0 (like arrays it starts at 0 and increments by 1 for each row returned).

There is more information in the manual if needed: http://us2.php.net/manual/en/function.mysql-result.php

Diablo84
livegirlloveAuthor Commented:
Diablo, I need to start paying you for all the quick help....Thanks a lot!!  It works perfectly.  
Diablo84Commented:
*laughing*, glad i could help :)

Diablo84
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.