Sortering af SQL data
Hej,Har denne MySQL tabel:
+------------------+----------------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+----------------------+------+-----+---------------------+-------+
| date_created | datetime | | | 0000-00-00 00:00:00 | |
| rating | tinyint(3) unsigned | | | 0 | |
| version | varchar(30) | | | | |
| region | tinyint(3) unsigned | | | 0 | |
| audio_format | varchar(30) | | | | |
| year_produced | smallint(4) unsigned | | | 0 | |
| genre | varchar(30) | | | | |
| title | varchar(100) | | | | |
| catalogue_number | varchar(40) | | PRI | | |
+------------------+----------------------+------+-----+---------------------+-------+
Jeg har så forsøgt mig med denne kode:
$result = mysql_query("SELECT title, genre, rating, year_produced, version, audio_format, region from dvds")
or die(mysql_error());
echo "<table border='0'>";
echo "<tr> <th>title</th> <th>genre</th> <th>Year</th> <th>Audio</th> <th>Region</th> <th>Version</th> <th>Rating</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['title'];
echo "</td><td>";
echo $row['genre'];
echo "</td><td>";
echo $row['rating'];
echo "</td><td>";
echo $row['year_produced'];
echo "</td><td>";
echo $row['version'];
echo "</td><td>";
echo $row['audio_format'];
echo "</td><td>";
echo $row['region'];
echo "</td></tr>";
}
echo "</table>";
Men listen vises desværre i denne rækkefølge:
title genre Year Audio Region Version Rating
Hvad gør jeg forkert? Går udfra det har noget med mit mysql_fetch_array kald at gøre, men jeg er sgu for newbie til at finde en "fejl" her. :o)
/Greg
