I'm sure there's a better way than the one I'm using to do what I want to do. I'm trying to select items from a database and order them by "category", which is one of the columns of the table I use. Then, I want the page to display the items with the category as a title, appearing only once. Hopefully someone can help me improve my code :)
Here's what the table looks like : ____________________________ | category | year | title | stuff | ------------------------------------------ | theatre | year1 | title1| ... | ----------------------------------------- | movie | year2 | title2 | ... |
Here's what I want :
Here's the code I use :
$categorie = mysql_query("SELECT categorie FROM $nom",$connexion) or die(mysql_error());
$nb = mysql_num_rows($categorie);
for ($i = 0; $i<$nb; $i++) {
$perf = mysql_result($categorie,$i);
$item[] = $perf;
}
$reduc = array_unique($item);
foreach($reduc as $genre) {
echo "