I’ve got an html table set up displaying MySQL data with a dropdown that allows you to choose whether to sort the data by Subgroup, Name or Partner. You can see it [URL=”http://myklwebs.com/myklmecha/database/g1sort.php”]here
What I would like to do is add sort options like ‘sort by Subgroup then Name’ but I don’t know how to do this. I know what php code to use achieve this in an un-sortable page but I don’t know how to put that into a dropdown. I don’t even know what keywords to use to search online! Can this code be edited to add some combined sort options or do I need totally different code?
Here’s the code I’m using:
[code=php]
<?php include(‘config.php’);
$query = “SELECT * FROM TransformersLog WHERE Series = ‘Generation 1’ Order By Faction”;
$res = mysql_query($query);
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Mykl’s Transformers Log</title>
<script src=”http://code.jquery.com/jquery-1.9.1.min.js”></script>
<script>
function dynamic_Select(dropdown) {
$.ajax({
type: “GET”,
url: ‘g1values.php’,
data: “ch=” + dropdown,
dataType: “html”,
success: function(html){ $(“#txtResult”).html(html); $(“#firstresult”).css(“display”, “none”); }
});
}
</script>
</head>
<body bgcolor=”#999999″>
<div style=”margin-left: 100px;”>
<form name=”ajaxlearning” id=”ajaxlearning”>
Sort By:<select name=”dropdown” id=”dropdown” onchange=”dynamic_Select(this.value)”>
<option value=””>Select Filter</option>
<option value=”Subgroup”>Subgroup</option>
<option value=”Name”>Name</option>
<option value=”Partner”>Partner</option>
</select>
</form>
<div id=”txtResult”>
</div>
<div id=”firstresult”>
<table id=”mytable” cellspacing=”0″ summary=”Mykl’s Transformers Log”>
<caption>Mykl’s Transformers Log</caption>
<tr>
<th>Year</th>
<th>Series</th>
<th>Faction</th>
<th>Subgroup</th>
<th>Name</th>
<th>Partner</th>
</tr>
<?php
while($row = mysql_fetch_array($res))
{
echo ‘<tr class=”alt”>
<td>’.$row[‘Year’].'</td>
<td>’.$row[‘Series’].'</td>
<td>’.$row[‘Faction’].'</td>
<td>’.$row[‘Subgroup’].'</td>
<td>’.$row[‘Name’].'</td>
<td>’.$row[‘Partner’].'</td>
</tr>’;
}
?>
</table></div>
</div>
</body>
</html>
[code=php]
<?php
include(‘config.php’);
$order = $_GET[‘ch’];
if($order!=”)
{
$query = “SELECT * FROM TransformersLog WHERE Series = ‘Generation 1’ Order By Faction , $order ASC”;
}
else
{
$query = “SELECT * FROM TransformersLog WHERE Series = ‘Generation 1’ Order By Faction “;
}
$res = mysql_query($query);
?>
<table id=”mytable” cellspacing=”0″ summary=”Mykl’s Transformers Log”>
<caption>Mykl’s Transformers Log</caption>
<tr>
<th scope=”col”>Year</th>
<th scope=”col”>Series</th>
<th scope=”col”>Faction</th>
<th scope=”col”>Subgroup</th>
<th scope=”col”>Name</th>
<th scope=”col”>Partner</th>
</tr>
<?php
while($row = mysql_fetch_array($res))
{
echo ‘<tr>
<td>’.$row[‘Year’].'</td>
<td>’.$row[‘Series’].'</td>
<td>’.$row[‘Faction’].'</td>
<td>’.$row[‘Subgroup’].'</td>
<td>’.$row[‘Name’].'</td>
<td>’.$row[‘Partner’].'</td>
</tr>’;
}
?>
</table>