表排序javascript使用选择选项菜单
table sorting javascript using select option menu
我试图对从数据库中检索的一些数据进行排序
首先,用户将从选择选项菜单中选择要显示哪个国家的数据
在之后,下一页将使用sort asc/desc函数
显示表中的特定数据这是我的代码
首页test.html
<form action="showDB1.php" method="post">
<table border="0">
<tr>
<th colspan="3">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 colspan="3">
<input type="submit" name="formSubmit" value-"Submit">
</td>
</table>
</form>
这是我的代码,用于在用户选择要显示哪个国家的数据后显示数据showDB1.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 == TRUE) {
$order = "";
$sort = "asc";
$sql = "SELECT wipo_applicant1_city, applicant1_addr1 FROM auip_wipo_sample";
if(isset($_GET['orderby'])){
$order = $_GET['orderby'];
$sort = $_GET['sort'];
//limiting the possible values of order/sort variables
if($order != 'wipo_applicant1_city' && $order != 'applicant1_addr1')$order = "applicant1_addr1";
if($sort != 'asc' && $sort != 'desc')$sort = "asc";
$sql = "SELECT wipo_applicant1_city, applicant1_addr1 FROM auip_wipo_sample WHERE applicant1_country='$country' ORDER BY ".mysql_real_escape_string($order)." ".$sort;
//here we reverse the sort variable
if($sort == "asc"){
$sort = "desc";
}
else{
$sort = "asc";
}
}
// query to get all US records
}
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
$row_counter = 0;
$icon = "";
echo "<table border='"1'" cellspacing='"0'">'n";
echo "<tr>'n";
// first column
echo "<th>";
$icon = "";
if($order == "wipo_applicant1_city"){
if($sort == "asc"){
$icon = "<img src='"images/up.png'" class='"arrowSpace'"/>";
}
if($sort == "desc"){
$icon = "<img src='"images/down.png'" class='"arrowSpace'"/>";
}
}
//print the result
echo "<a href='index.php?orderby=wipo_applicant1_city&sort=".$sort."'>City</a>".$icon;
echo "</th>'n";
// second column
echo "<th>";
$icon = "";
if($order == "applicant1_addr1"){
if($sort == "asc"){
$icon = "<img src='"images/up.png'" class='"arrowSpace'"/>";
}
if($sort == "desc"){
$icon = "<img src='"images/down.png'" class='"arrowSpace'"/>";
}
}
echo "<a href='index.php?orderby=applicant1_addr1&sort=".$sort."'>Address</a>".$icon;
echo "</th>'n";
echo "</tr>";
//fetch the result
while($row = mysql_fetch_array($result))
{
if($row_counter % 2){
$row_color="bgcolor='#FFFFFF'";
}else{
$row_color="bgcolor='#F3F6F8'";
}
echo "<tr class='"TrColor'" ".$row_color.">";
echo "<td>" . $row['wipo_applicant1_city'] . "</td>'n";
echo "<td>" . $row['applicant1_addr1'] . "</td>'n";
echo "</tr>";
$row_counter++;
}
Print "</table>";
我的问题是,当用户选择任何国家的选择选项时,所有的数据都显示出来。
预期的结果应该是只有特定的数据需要显示
谁能解决这个问题?
谢谢
从你的代码来看,问题可能是你有一个破折号而不是等号在你的输入按钮
<input type="submit" name="formSubmit" value-"Submit">
应该value="Submit"
我会看下面的if语句然后
if(isset($_GET['orderby'])){
因为在你的表单的初始提交你发送post语句,你的sql语句没有被调用,因为它是包装在里面的if语句。
将以下内容移出语句
$order = "";
$sort = "asc";
$sql = "SELECT wipo_applicant1_city, applicant1_addr1 FROM auip_wipo_sample";
当然还要加上这个让国家选择显示
WHERE applicant1_country='$country'
相关文章:
- CKeditor:更改对话框中的默认选择选项
- 如何在从多选下拉列表中选择选项值时动态生成文本框
- AngularJs列表ng单击以选择选项转换
- 使用基于文本的 Jquery 选择选项
- 当选择值x时,Javascript需要在正确的位置显示文本区域,从而循环通过具有选择选项的表单
- 在php和mysql中选择选项.一旦选择了选项,就列出我的sql数据库数据
- 选择选项时如何显示警报
- 使用php动态更改选择选项
- 选择“选择选项”时显示文本.怎么做
- LEAFLET地图和带有选择选项的标记-ANGULARjs
- 使用js将动态内容添加到选择选项列表中
- 用于使用javascript循环选择选项
- AngularJS-选择选项并在函数中使用它
- 禁用/启用基于单选/选择选项所选Javascript的文本框
- 如何使用jQuery隐藏与选择选项相关的选择选项列表
- 选择选项是添加或删除事件
- 使用jQuery向“选择选项”添加默认属性
- 构建HTML选择字段并使用JavaScript数组选择选项
- 带有动态选择选项的Firefox html5验证异常
- 只有当Angular从资源对象检索数据时,才选择选项元素