Hello,
I'm sorry if you can't understand what I'm trying to do, but it's kind of hard to explain something you have no idea of doing. :p
Anways...
I currently have a database of ARTISTS and SONGS, and I can sort them pretty easily, either by SONG, ARTIST, or you can even sort by letter. See here:
http://www.splix.net/music.php
Ok, now what I want to do is, say if you click on the letter G, all the Artists with the letter G are displayed. Right under that there is a Sort by: area, and if the user were to click on say SONG, it would sort the Artists beggining with the letter G by song.
I kind of confused myself there, but I have seen sites that have done this before and it kind of looks like this:
http://www.example.com/music.php?artist=a&sort=song
How would I do this?
I am currently calling my database and doing all the sorting like this:
<?php
$db = mysql_connect("localhost", "splix", "PASS");
mysql_select_db("splix",$db);
if($_GET['artist']) {
$artist = $_GET['artist'];
$query = "SELECT * FROM `mp3` WHERE artist LIKE '$artist%' ORDER BY artist ASC";
}
else if ($_GET['sort'] == 'song') {
$song = $_GET['song'];
$query = "SELECT * FROM `mp3` ORDER BY song ASC";
}
else if ($_GET['sort'] == 'artist') {
$artist = $_GET['artist'];
$query = "SELECT * FROM `mp3` ORDER BY artist ASC";
}
else {
$query = "SELECT * FROM mp3 ORDER BY artist ASC";
}
$result = mysql_query($query);
$numofrows = mysql_num_rows($result);
echo "<TABLE width='100%'>";
echo "<TR><TD width='50%'><b><span class='main'>Artist</b></TD><TD width='50%'><b><span class='main'>Song</b></TD></TR><br><tr></tr>";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result);
if($i % 2) {
echo "<TR bgcolor=DADADA>";
} else {
echo "<TR bgcolor=F0F0F0>";
}
echo "<TD class='main'>".$row['artist']."</TD><TD class='main'>".$row['song']."</TD>";
echo "</TR>";
}
echo "</TABLE>";
?>
For the individual letter links I have this:
<a href="music.php?artist=a"><? if ($artist == 'a')
echo "<b>A</b>";
else echo "A"; ?></a>
And for the Sort by links it's the same idea:
<? if ($sort == 'song')
echo "<b>SONG</b>";
else echo "SONG"; ?></a>
Now I know this probably isn't the most efficient way of doing anything, but it works for now.
So basically I am trying to make my site more dynamic, and I think this is the last thing I am going to do today if I figure it out.
Any ideas?