On Oct 29, 2008, at 7:32 PM, j0hncage wrote: > Realizing my original post might be rather 'excessive' :-) > > Can anyone tell me how to include "DISTINCT name" in the following? > I've tried numerous variations and haven't been able to make it work > but think it must be possible. I'm after a return of a single name > where there may be a dozen or so 'Debra', only wanting it returned one > time for counting purposes. Thanks again for any help. John > > $query = "SELECT * FROM $table WHERE 1 = 1 "; > if($month != "All") $query .= "and month = '".$month."'"; > if($year != "All") $query .= "and year = '".$year."'"; > if($name != "All") $query .= "and name = '".$name."'"; > > $result = mysql_query($query); > > $number = mysql_numrows($result);
Why don't you do something like: $query = "SELECT name, count(*) AS my_count FROM $table WHERE 1 = 1 "; if($month != "All") $query .= "and month = '".$month."'"; if($year != "All") $query .= "and year = '".$year."'"; if($name != "All") $query .= "and name = '".$name."'"; $query .= " GROUP BY name; You then get a result set of name and my_count. -D. Israel [EMAIL PROTECTED] http://www.customcodebydan.com AIM: JudoDanIzz [Non-text portions of this message have been removed]