I was wondering... I want to count the times a certain value is in the database... I don't know the value dough...
For instance ...
I have a table visitors
with
visit_id
firstname
lastname
gender
etc...
now I want to create a report that shows all the firstnames (but only once) and I want to show the number that a firstname exists..
I know I can do something like
But I was wondering if there is a better way of doing something like this...PHP Code:$sql = "select distinct firstname from visitors";
$result = @mysql_query($sql);
While($row = mysql_fetch_array($result))
{
$name = $row["firstname"]
echo "firstname = $name";
$sql2 = "count("firstname") as num where firstname = '$name'";
$result2 = ($sql2);
echo $result["num"];
}
?>
Greets
Peanuts





Bookmarks