我试图创建一个按钮,其功能是对数据进行降序或升序排序。但是,我不知道该怎么做
我在互联网上做了一些研究,但没有一个给出答案。
有谁知道怎么做或一些可以作为参考的源代码???
这是我的代码 test.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Data Mining</title>
</head>
<body>
<form action="showDB.php" method="post">
<table border="0">
<tr>
<th>test</th>
</tr>
<tr>
<td>Select Foreign Agent Country</td>
<td></td>
<td>
<select name="country">
<option value="US">United States</option>
<option value="NZ">New Zealand</option>
<option value="JP">Japan</option>
</select>
</td>
</tr>
<td>
<input type="submit" name="formSubmit" value-"Submit">
</td>
</table>
</form>
</body>
</html>
显示数据库.php
<?php
//connect to server
$connect = mysql_connect("localhost", "root", "");
//connect to database
//select the database
mysql_select_db("fak_databases");
//submit button
if($_POST['formSubmit'] == "Submit")
{
$country = $_POST['country'];
}
//query the database
if($country == 'US') {
// query to get all US records
$query = mysql_query("SELECT * FROM auip_wipo_sample WHERE applicant1_country='US'");
}
elseif($country == 'NZ') {
// query to get all AUD records
$query = mysql_query("SELECT * FROM auip_wipo_sample WHERE applicant1_country='NZ'");
}elseif($country == 'JP') {
// query to get all AUD records
$query = mysql_query("SELECT * FROM auip_wipo_sample WHERE applicant1_country='JP'");
} else {
// query to get all records
$query = mysql_query("SELECT * FROM auip_wipo_sample");
}
//fetch the result
Print "<table border cellpadding=3>";
//ascending descending button
Print "<tr><th colspan='2'><input type='submit' name='asc_sort' value-'Asc'></input></th></tr>";
while($row = mysql_fetch_array($query))
{
Print "<tr>";
Print "<td>".$row['invention_title'] . "</td>";
Print "<td>".$row['invention-title'] . " </td></tr>";
}
//sorting the data, I got from internet but doesn't work
if(isset($_POST['asc_sort']) && !empty($_POST['asc_sort']) && $_POST['asc_sort']==1)
{
$query = "SELECT * FROM auip_wipo_sample ORDER BY invention_title ASC";
}else{
$query = "SELECT * FROM auip_wipo_sample ORDER BY invention_title DESC";
}
Print "</table>";
?>