Forum Moderators: coopster
Little things like this seem to get me stuck although I know there is a simple answer I'm missing somewhere.
I am trying to get the last 100 albums I entered into my database using the album_id (Highest being the latest entry) then sort them alphabetically using the album_title column.
I can get the latest 100 easily but cannot figure out how to also sort the results by the album_title before I display them.
This is what I have so far which gets what I want but not in alphabetical order.
<?php
$sqlquery = mysql_query("SELECT * FROM albums ORDER BY album_id desc limit 100", $db);
while ($result = mysql_fetch_row($sqlquery))
{
echo "<a href='music_info.php?album_id=$result[0]'><span style='text-decoration: none'>$result[1]</span><br></a>";
}
?>
I have been trying to add a second ORDER BY to the query like so.
$sqlquery = mysql_query("SELECT * FROM albums ORDER BY album_id desc limit 100 ORDER BY album_title", $db);
but this obviously isn't the way I should be doing it.
HELP PLEASE!
This query does exactly what I wanted.
$sqlquery = mysql_query("SELECT * FROM albums where album_id >= 3739 ORDER BY album_title", $db);
As the amount of rows gets higher when I add to the database I will just have to count the rows then subtract 100 from the result and use that in the query.
I know I've seen info about counting rows somewhere and am going in search of the answer but please advise if possible incase I get lost along the way
Thanks in advance
Glad to be here.
Sometimes it seems we can sit for hours trying to work something out then when we write out the question on a forum and read it back it somehow becomes a little more clear.
But the answers were mostly found by browsing through the rest of the forum and picking up bits here and there.
Great site.