通过javascript和php动态排序表以及其他一些选择标准
Dynamically sorting the table along with other few selection criteria via javascript and php
我有两部分
第一部分是基于各种输入构建动态查询
第二部分是对结果表ASC/DESC 进行排序
PHP部分测试良好,运行良好
if( !empty( $_REQUEST['cond1'] ) ){
$sql[] = mysql_escape_string( $_GET['cond1'] );
}
等等…
直到最后条件
构建查询并获取记录
排序顺序的触发器如下
<table>
<th><a href="orderby=name&obtype=A">Name</a></th>
</table>
当我点击href 时
作为GET PARAM通过的所有选择标准都将丢失
现在,查询仅使用字段的SORT ORDER来运行。
如何正确附加
orderby=name&obtype=A
要玩window.location,我正在使用以下功能
// Function gets a param value from a URL when given a param name
function getUrlParameter( url, name ) {
name = name.replace(/['[]/,"'''[").replace(/[']]/,"''']");
var regexS = "[''?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( url );
if( results == null )
return "";
else
return results[1];
}
//Attaching Event handler for the heading and
//finding what column heading is clicked
$("#result-tbl th").click(function(ev){
ev.preventDefault();
// Build a URL from the orderbytriggered
// Problem is when I click the first column it works
// When i click the second, third, It keeps on adding all the order by
// column which is not wanted.
// Pls help me in finding the problem.
var c = getUrlParameter( ev.target.href , 'orderby' ),
d = getUrlParameter( ev.target.href , 'obtype' ),
newurl = window.location.href + '&orderby=' + c + '&obtype=' + d;
alert( newurl );
window.location.href = newurl;
});
当前的GET PARAMS将在$_SERVER['QUERY_STRING']
中提供给您。
html:的示例输出
<?php
if ($_SERVER['QUERY_STRING']) {
myQueryString = $_SERVER['QUERY_STRING'] + "&orderby=name&obtype=A"
} else {
myQueryString = "?orderby=name&obtype=A"
}
?>
<table>
<th><a href="<?=myQueryString?>">Name</a></th>
</table>
相关文章:
- 下拉选择可自动更改第二个下拉选择
- 如何使用jQuery选择下拉列表的值
- 如何使Javascript动态html表及其上的事件
- jquery点击函数select&取消选择
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 隐藏选择's optgroups及其内容(所选内容除外)
- TypeScript 或 JS- 如何在 HTML 中选择一个元素及其所有子元素
- 如何选择以 1 递增的多个类及其匹配的子类
- $(这个)选择器和他的后代
- 如何在jquery中选择元素及其子元素
- 如何使用Jquery选择此特定的td元素及其文本
- 如何使用Jquery选择第一个td元素及其文本
- 选择tr及其“所有子元素”;-查找jquery选择器
- 选择父节点及其所有兄弟节点
- 他没有选择ng-model change angularjs
- Select2 multiselect -选择一个组及其所有子组,但允许在未选择组时选择多个子组
- 选择/option标签及其id
- 我建立了一个选择,当我刷新页面时,我需要他显示我以前选择的内容
- 自定义选择框,如果没有则向上滑动自定义选择框及其子框为click
- 优化jQuery选择器的最佳方法及其原因