我有两部分
第一部分是基于各种输入构建动态查询
第二部分是对结果表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>