arrays
Hi,
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 :
Any help would be greatly appreciated !
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 "<fieldset>";
echo "\n<legend>$genre</legend>";
echo "\n<table cellspacing=\"10\" cellpadding=\"0\">";
$liste = mysql_query("SELECT * FROM $nom WHERE categorie LIKE '" . $genre . "' ORDER BY annee DESC",$connexion);
while ($row = mysql_fetch_assoc($liste)) {
$annee = $row['annee'];
$titre = $row['titre'];
$complement = $row['complement'];
echo "\n <tr><td><strong>$annee</strong></td><td><strong>$titre</strong></td><td>$complement</td></tr>";
}
echo "\n</table>";
echo "</fieldset>";
}
Any help would be greatly appreciated !
