Hello, I'm working on a MySQL database query with PHP where I'm trying
to patch in an ability to select a distinct 'name' from the query
where the current 'All' queries all records for a given period and
'All Unique' would only bring back unique names so I'd basically end
up with:

Debra
Edward
Richard
Sandra

(probably showing just the 1st record within the table for a given
name).  What this does is allow a quick glance count on how many
different people had an entry for the period.

Currently for example, 'All' gives me all records for those names as
follows:

Debra
Debra
Debra
Debra
Debra
Edward
Edward
Edward
Richard
Richard
Richard
Richard
Richard
Richard
Sandra
Sandra

the query input screen might look like this:
<tr><td>Name:</td>
  <td><select name="name" maxlength="15">
        <option value = "All">All</option>
        <option value = "All Unique">All Unique</option>
        <option value = "Debra">Debra</option>
        <option value = "Edward">Edward</option>
        <option value = "Richard">Richard</option>
        <option value = "Sandra">Sandra</option>
      </select>
  </td>
</tr>

The second page that I'm dealing with currently looks like this:
$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);

and I'm hoping to integrate perhaps else/if to include IF 'All Unique'
is selected in the drop down menu, QUERY DISTINCT NAME ORDER BY NAME,
etc...  Can someone help?

Thanks,
John

Reply via email to