2013-04-10 5 views
1

에 $ _GET 변수를 전달합니다. 여러 MySQL 쿼리의 테이블을 표시하는 PHP 페이지가 있고 그 결과에서 열 결과를 정렬하는 JavaScript 함수를 사용할 수 있습니다. 문제가 해결되면 결과를 새로 고쳐야합니다. (메타 새로 고침과 함께) 10 초마다 또는 그와 같은 쿼리가 잘 작동하는 경우 문제는 열 정렬 후 새로 고침입니다. 페이지가 새로 고침되면 정렬도 다시 설정됩니다. 다음은 정렬 함수 스 니펫입니다. 여기 자바 스크립트 함수

<script> 
    function tablesort(which){ <-----I tried using the $_GET method you suggested 
           <-----But i get a "missing formal parameter" error 
           <-----When also using this suggestion and use the 
           <-----"onclick" i get a "tablesort" is not defined 
           <-----error 
$(document).ready(function(){ 
if(which == '1.0'){<!--This sorts the pause row, descending --> 
$("#Mtable").tablesorter({sortList: [[1,0]]}); 
} 
if(which == '2.1'){<!--This sorts the total dialer row, descending --> 
$("#Mtable").tablesorter({sortList: [[2,1]]}); 
} 
if(which == '3.0'){<!--This sorts Wrap-up time row, descending --> 
$("#Mtable").tablesorter({sortList: [[3,0]]}); 
} 
if(which == '4.1'){<!--This sorts donation amount row, descending --> 
$("#Mtable").tablesorter({sortList: [[4,1]]}); 
} 
if(which == '5.1'){<!--This sorts Up-sale row, descending --> 
$("#Mtable").tablesorter({sortList: [[5,1]]}); 
} 
if(which == '6.1'){<!--This sorts the Monthl donation row, descending --> 
$("#Mtable").tablesorter({sortList: [[6,1]]}); 
} 
if(which == '7.1'){<!--This sorts the verified sales row, descending --> 
$("#Mtable").tablesorter({sortList: [[7,1]]}); 
} 
if(which == '8.1'){<!--This sorts the calles per hour row, descending --> 
$("#Mtable").tablesorter({sortList: [[8,1]]}); 
} 
if(which == '9.1'){<!--This sorts the payments per hour row, descending --> 
$("#Mtable").tablesorter({sortList: [[9,1]]}); 
} 
if(which == '10.1'){<!--This sorts the average sale row, descending --> 
$("#Mtable").tablesorter({sortList: [[10,1]]}); 
} 
if(which == '11.1'){<!--This sorts the sales total row, descending --> 
$("#Mtable").tablesorter({sortList: [[11,1]]}); 
} 
    }); 
    } 
    </script> 

때문에 그래서 것 $ _GET 유사한 URL에 onlcick에서 변수 데이터를 전달하고자 새로 고침 메신저의 테이블 '

 Sort by: 
<a onclick="tablesort('1.0')"> Lowest Pause<a/>&nbsp &nbsp 
<a onclick="tablesort('2.1')"> Highest Dialer<a/>&nbsp &nbsp 
<a onclick="tablesort('3.0')"> Best Wrap-up<a/>&nbsp &nbsp 

를 정렬 링크입니다 법한 그런 다음 정렬 기능을 읽습니다.

2.1 <를 = 로컬 호스트/dbtabke.php은? ---- 정확한 URL의 예는 사전에

그 작업을 수행하는 방법에 대한 도움

크게 감사하겠습니다 감사를 사용.

@prabeen 기리 난 덕분에 다시

+0

'$의 갔지'(... + sort_by_var '/ dbtabke.php? Mtable = 로컬 호스트') 도움이되기를 바랍니다? –

+0

PHP 페이지를 통해 데이터를 다시로드하는 AJAX 요청의 일부로 쿼리 변수를 전달하려고합니다. –

+0

@Mathew Darnell, 새로 고침 부분 때문에 URL을 통해 javascript 함수에 tablesport ('1.0') "데이터를 전달하고 싶습니다. – Iz3k34l

답변

0

을 생각하기 때문에 tablsort() 기능에 여기에 코드가 있습니다. 모든 사람의 입력을위한

<body> 
    <!--This gets the element from the URL to set the Sorting, so the page 
     can be refreshed without losing the sorting--> 
    <body onload="sorttable.innerSortFunction.apply(document.getElementById('<?php echo $_GET["id"]; ?>'), [])"> 

    <!--table headers that are used to determine columns to sort by--> 
    echo "<th id=\"dialertime\">".ucfirst("Dial Time")."</th>\n"; 
    echo "<th id=\"pausetime\">".ucfirst("Pause Time")."</th>\n"; 

    ...*other table info* 
    <!--links that sort the specific row--> 
    <a href="?id=wrap-by-time"> Wrap-up time<a/>&nbsp &nbsp 
    <a href="?id=wrap-by-percent"> Wrap-up %<a/>&nbsp &nbsp 
    </body> 

덕분에, 그것은

0

당신은 반드시 정렬 순서를 유지하기 위해 GET 방식을 사용하지 않아도, 완전한 기능을 제공하고 있습니다.

또한 쿠키를 사용하여 정렬 순서를 저장할 수 있습니다. 이렇게하면 코드가 더 깨끗 해집니다.

function setCookie(c_name,value,exdays) 
{ 
var exdate=new Date(); 
exdate.setDate(exdate.getDate() + exdays); 
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); 
document.cookie=c_name + "=" + c_value; 
} 

function getCookie(c_name) 
{ 
var i,x,y,ARRcookies=document.cookie.split(";"); 
for (i=0;i<ARRcookies.length;i++) 
{ 
    x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); 
    y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); 
    x=x.replace(/^\s+|\s+$/g,""); 
    if (x==c_name) 
    { 
    return unescape(y); 
    } 
    } 
} 

전화 당신이 순서를 정렬하고 매개 변수로 정렬 순서를 전달하는 setCookie() 기능.

처음으로 페이지를로드하거나 새로 고침 할 때 동일한 정렬 함수를 호출하고 getCookie()을 호출하여 정렬하기 전에 쿠키 값을 가져 와서 정렬 순서로 설정하십시오.

GET을 사용하려는 경우 페이지가 새로 고침 될 때 작업을 수행하므로 문서가 준비되면이 함수를 tablesort()라고 부르기 바랍니다.

tablesort('<?php print $_GET['MTable']?>') ; 

참고 : 매개 변수가 유효한지 확인하지 처음으로 페이지가로드, GET 변수가 비어있을 때, 나는 다음과 같은 사용하여 $ _GET하고 끝났다