Page 1 of 1

COUNT(*) confusion

Posted: Sun Mar 21, 2004 10:22 pm
by Steveo31
I'm trying to get the total rows in a given table. Then, if that number is bigger than __ display another message.

For learning sakes (I don't really have a travel agency ;)) I made a DB called Vacation. From there it has tables called "jamaica", "bolivia", and "haiti". Those each have 2 rows, "name" and "total". The total is an auto incremental MEDIUMINT.

Here's the part I think I am having problems with:

Code: Select all

$getTotal = "SELECT COUNT(total) FROM jamaica";

$totalResult = mysql_query($getTotal, $db);

if($totalResult > 4){
	echo "The trip is filled.  Please try one of out other options.";
}
How would I get it to see that the count is more than 4 (which it is in my case)?

Posted: Sun Mar 21, 2004 10:53 pm
by coreycollins
Just do it like you would normally so you would use:

Code: Select all

$getTotal = "SELECT COUNT(total) FROM jamaica";
$totalResult = mysql_query($getTotal, $db);
$row = mysql_fetch_row($result);
if($row[0]> 4){
   echo "The trip is filled.  Please try one of out other options.";
}

Posted: Sun Mar 21, 2004 10:59 pm
by Steveo31
Ah thanks. Oh, and it's

Code: Select all

$row = mysql_fetch_row($totalResult);
Not

Code: Select all

$row = mysql_fetch_row($result);
:)

I know, it's habit just for "$result"....

Posted: Sun Mar 21, 2004 11:02 pm
by coreycollins
lol yeah I didn't notice you had $totalResult.