Here's the thing. I have a table with the fields Name, HP, MP, AP Gil. The information that goes in this table is obtained from a Mysql database. Above this table i have the letters from A - Z pertaining to the names. E.g. If "A" is chosen, it would display only the items that are in the group "A". Now the problem is:
1) I want it so when the user chooses to sort by Name, HP, MP, AP or Gil (whichever option they choose), the items in the table get sorted in the matter that the user chose. E.G. If the use chose to sort by "Name" it would sort everything in the table by Name. If user chose to sort by "HP" it would sort everything in the table by HP and so forth.
2) I want it so that when the user chooses a letter (A - Z), it only displays the items in the table pertaining to that letter. So, if user chose the letter "A", it would display only the items that are in the group "A". (There is a "group_letter" field in my database table btw). If user chose "B" it would display only "B" items and so forth. BUT, i want it so that even if it displayed the items that only pertained to that group, the sorting option would still be available and the user would be able to sort this time, the new items that show up pertaining to the letter chosen. If you are confused at this point, ill give you an example.
User chooses to view items by the letter "B". Table displays all items that are in group_letter B. The user also wants to sort by "name, hp, mp, ap or gil" these items that are displayed in the group_letter B.
So far, i have been able to create this coding:
<?php
if ( $letter ) {
$query = "SELECT * FROM statistics WHERE group_letter = '$letter'";
} else {
$query = "SELECT * FROM statistics ORDER BY id";
}
$result = mysql_query( $query ) or die ( "Query failed" );
?>
<table width="100%" border="0" cellpadding="2" cellspacing="0" valign="top">
<tr>
<td><font class="letter"><a href="?letter=#">#</a></td>
<td><font class="letter"><a href="?letter=a">A</a></td>
<td><font class="letter"><a href="?letter=b">B</a></td>
<td><font class="letter"><a href="?letter=c">C</a></td>
<td><font class="letter"><a href="?letter=d">D</a></td>
<td><font class="letter"><a href="?letter=e">E</a></td>
<td><font class="letter"><a href="?letter=f">F</a></td>
<td><font class="letter"><a href="?letter=g">G</a></td>
<td><font class="letter"><a href="?letter=h">H</a></td>
<td><font class="letter"><a href="?letter=i">I</a></td>
<td><font class="letter"><a href="?letter=j">J</a></td>
<td><font class="letter"><a href="?letter=k">K</a></td>
<td><font class="letter"><a href="?letter=l">L</a></td>
<td><font class="letter"><a href="?letter=m">M</a></td>
<td><font class="letter"><a href="?letter=n">N</a></td>
<td><font class="letter"><a href="?letter=o">O</a></td>
<td><font class="letter"><a href="?letter=p">P</a></td>
<td><font class="letter"><a href="?letter=q">Q</a></td>
<td><font class="letter"><a href="?letter=r">R</a></td>
<td><font class="letter"><a href="?letter=s">S</a></td>
<td><font class="letter"><a href="?letter=t">T</a></td>
<td><font class="letter"><a href="?letter=u">U</a></td>
<td><font class="letter"><a href="?letter=v">V</a></td>
<td><font class="letter"><a href="?letter=w">W</a></td>
<td><font class="letter"><a href="?letter=x">X</a></td>
<td><font class="letter"><a href="?letter=y">Y</a></td>
<td><font class="letter"><a href="?letter=z">Z</a></td>
</tr></table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" valign="top"><tr><td height="10"></td></tr></table>
<table bgcolor="666666" width="100%" border="0" cellpadding="2" cellspacing="1" valign="top">
<tr>
<td bgcolor="AEB09A" width="20%"><font class="main"><b>Name<a></b></td>
<td bgcolor="AEB09A" width="20%"><font class="main"><b>HP<a></b></td>
<td bgcolor="AEB09A" width="20%"><font class="main"><b>MP<a></b></td>
<td bgcolor="AEB09A" width="20%"><font class="main"><b>AP<a></b></td>
<td bgcolor="AEB09A" width="20%"><font class="main"><b>Gil<a></b></td>
</tr>
<?php
$bestiary = mysql_fetch_array( $result );
echo "<td><font class='main'>".$bestiary['name']."</td>";
echo "<td><font class='main'>".$bestiary['hp']."</td>";
echo "<td><font class='main'>".$bestiary['mp']."</td>";
echo "<td><font class='main'>".$bestiary['ap']."</td>";
echo "<td><font class='main'>".$bestiary['gil']."</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
?>
This so far has allowed the displaying by group_letter to work. However, i cannot seem to figure out how to get it to sort successfully at this stage. If anyone can help me... it'll be big big big help and very much appreciated. Thanks!