I am trying to querry a database to return the number of unique items in a row.
eg:
red
red
blue
black
black
black
green
would return
red 2, blue 1, black 3, green 1.
I am trying to do this using the following code, but am not sure if this is the best way. Ideas/Help?
setup SQL statement
$SQL = " SELECT DISTINCT FROM database_table WHERE color LIKE \"$color\";
execute SQL statement
$retid = mysql_db_query($database_name, SQL, $cid);
$numrows = mysql_num_rows($retid);
check for errors
if (!$retid) { echo( mysql_error()); }
else {
display results
while ($row = mysql_fetch_array($retid))
{
$idview = $row["id"];
$compname= $row["compname"];
$gender = $row["gender"];
}
}
Thanks