|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am trying to count the number of rows I have in a mysql table. I am trying to test to see if I am using the MySQL COUNT properly and I am apparently doing something wrong. I am coming up 2 short of what I can see in my DB. I have 21 rows in the table but when counting the rows, I keep having 19 returned. Here is the query I am using:
$event_id = 1; $active = "YES"; $teamresult = mysql_query ("SELECT COUNT(*) as Count FROM event_team WHERE event_id = $event_id AND active = '$active'"); $trow = mysql_result($teamresult, 0, 0); Any thoughts would be greatly appreciated on why I am getting the wrong result returned. THANKS IN ADVANCE!!! Mirlynn |
|
#2
|
||||
|
||||
|
My guess is, although you have 21 rows, only 19 have an event_id of whatever and an active value set to whatever
If you run that same command (with real values and not variables) directly against your database (not in a PHP script), you should see the same results. For the record, and because I love saying it, I recommend adding an or die() clause to your mysql_query statement. Code:
$teamresult = mysql_query($query) or die("MySQL ERROR ".mysql_errno().": ".mysql_error());
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Am I using mysql COUNT incorrectly? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|