Hi All,
Ive been reading through the archives, but couldnt find the answer to my problem. im trying to do sortable columns, and although i can query the datbase, and receive the results without a problem, i cant actually sort the data. hopefully someone can point me in the right direction.
<><><><><><><><><><><><><><><><><><><><><><>
<?php
mysql_connect( 'localhost', 'user', 'password' ) or die ( 'Unable to
connect.' );
mysql_select_db( 'tortl' ) or die ( 'Unable to select database.' );
// if $sortby isn't empty, then check to see which column we're sorting by
if( $sortby != "" ){
switch( $sortby ){
case "col1": $sql = "SELECT * FROM players ORDER BY id"; // sorts by column1
case "col2": $sql = "SELECT * FROM players ORDER BY name"; //
case "col3": $sql = "SELECT FROM players ORDER BY team";
// etc.
default: $sql = "SELECT FROM players"; // if $sortby isn't one of our values don't sort
}
}
// otherwise, don't sort
else {
$sql = "SELECT * FROM players";
}
$result = mysql_query( $sql ) or die ( 'Unable to execute query.' );
?>
<table border="1">
<tr>
<th><a href="roster.php?sortby=col1">id</a></th>
<th><a href="roster.php?sortby=col2">name</a></th>
<th><a href="roster.php?sortby=col3">team</a></th>
</tr>
<?php
while($row = mysql_fetch_array($result)){
?>
<tr>
<td><?=$row[0]?></td>
<td><?=$row[1]?></td>
<td><?=$row[2]?></td>
</tr>
<?php
}
?>
</table>
<><><><><><><><><><><><><><><><><><><><><><>
u can see it in action here:
http://tortl.tecmobowl.org/roster.php
any advice would be greatly appreciated.
Kimrari