Say i have a table called managers with 3 fields and i have 10 rows.
id AgeGroup name
1 a 1
2 a 2
3 a 3
4 b 4
5 b 5
6 c 6
7 d 7
8 d 8
9 d 9
10 e 10
code:
$con = mysql_connect("localhost","username","password");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);
$query = "SELECT * FROM managers ORDER BY AgeGroup ASC";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
echo'<ul>';
if (mysql_num_rows($result)>0) {
while($row = mysql_fetch_array($result)) {
echo'<li>'.$row['AgeGroup'].'</li>';
}
}
echo'</ul>';
I want to be able to echo the agegroup field but have no repeats.
Ie the output would be :
a
b
c
d
e
any help would be appreciated
Add the GROUP BY clause in your query.