SELECT DISTINCT
Posted: Tue Aug 12, 2008 8:33 am
Hi all,
Can someone please point me in the right direction.
If I have a table called banks2 with a field called name and it could have any number of entries that are the same.
Eg
Netbank
Netbank
Commonwealth
Netbank
Westpac
How would I loop through to get the number of times each name appears is it SELECT DISTINCT or will that only give me each unique name and therefore 1 entry. I have the code below to get one name.
Can someone please point me in the right direction.
If I have a table called banks2 with a field called name and it could have any number of entries that are the same.
Eg
Netbank
Netbank
Commonwealth
Netbank
Westpac
How would I loop through to get the number of times each name appears is it SELECT DISTINCT or will that only give me each unique name and therefore 1 entry. I have the code below to get one name.
Code: Select all
$query = 'SELECT * FROM `banks2` WHERE '
. ' `name`= \'Commonwealth\' LIMIT 0, 30 ';
$result = @mysql_query ($query); // Run the query.
$num1 = mysql_num_rows($result);
if ($num > 0) { // If it ran OK, display the records.
} else { // If it did not run OK.
echo '<p class="error">There are currently no entries.</p>';
}
echo '
<tr><td >Commonwealth Bank</td><td ><img src="includes/column.gif" width="'.( $num * 10).'" height="10" /> '.$num.'</td></tr>
';