Question : ajax passing error, one of the vars is not getting through

Ok I just cannot see where i'm going wrong here. I am trying to filter/sort my database results through php using ajax.I have a js directory which contains projects.js and projects.php that actually puts together the sql statement and does its job. It is then displayed in paging_holder on another page in the root directory. It seems to work for the most part as results are displayed but there is a problem occuring when i try to ASC or DESC the data.

As far as I can tell from going directly to localhost/js/project.php(querying the database without the javascript) and manually writing in all the GET variables the php works as it should, so my problem must lie within the javascript. For some reason one of the GET variables (the $descasc) is not being passed through the ajax properly while everything else is. Here is the php which generates the mysql statement and the link.

//create get rows query including orderby and asc/desc and number of rows per pageetc
if (isset($_GET['zone'])) {
$zone   =   $_GET['zone'];
      $zonesql  =   "JOIN    link_projects_zones
                   ON      projects.proj_ID             =   link_projects_zones.proj_ID
                   WHERE   link_projects_zones.zone_ID   =   {$zone}";
}
 
if (isset($_GET['orderby'])) {
      $orderby = $_GET['orderby'];
      switch ($orderby) {
          case "title":
              $orderbysql=" ORDER BY proj_Title ";
        break;
               case "budget":
              $orderbysql=" ORDER BY proj_Budget ";
        break;
            case "user":
              $orderbysql=" ORDER BY user_ID ";
        break;
      }
      
      if (isset($_GET['ascdesc'])) {
            $ascdesc1 = $_GET['ascdesc'];
            switch ($ascdesc1) {
                case "ASC":
                        $ascdescsql ="ASC";
                    $ascdesc="DESC";
              break;
                     case "DESC":
                        $ascdescsql ="DESC";
                    $ascdesc="ASC";
              break;
            }
      } else {$ascdesc = "ASC";
      }            
}
$sql = "SELECT * FROM projects " . $zonesql . $orderbysql . $ascdescsql . " LIMIT $offset, $rowsperpage";
echo $sql;
echo $ascdescsql;
echo $ascdesc;

//////////////////////////////////////////////////////////////////////////////////////
//headers sort bys
?>

Title

Below is my javascript, everything apart from the ascdesc is being passed correctly.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
var xmlHttp=null;
 
function paging(currentpage, orderby, ascdesc, zone)
{
        xmlHttp=GetXmlHttpObject();
 
        if (xmlHttp==null)
        {
                alert ("Your browser does not support AJAX!");
                return false;
        }
 
                var url="js/projects.php";
                url=url+"?currentpage="+encodeURIComponent(currentpage);
				url=url+"&orderby="+encodeURIComponent(orderby);
				url=url+"&ascdesc="+ascdesc;
				url=url+"&zone="+encodeURIComponent(zone);
                url=url+"&sid="+Math.random();
 
                var newfield="project_paging_holder";
                newfield=newfield;
                                
		document.getElementById(newfield).innerHTML = '';
           
				
                xmlHttp.onreadystatechange=function(){stateChanged(newfield)};
                xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
  
 
}
function stateChanged(newfield)
{
 
        if (xmlHttp.readyState==4)
        {
                document.getElementById(newfield).innerHTML=xmlHttp.responseText; 
        }
}
 
function GetXmlHttpObject()
{
        var xmlHttp=null;
        try
        {
                // Firefox, Opera 8.0+, Safari
                xmlHttp=new XMLHttpRequest();
        }
        catch (e)
        {
                // Internet Explorer
                try
                {
                        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {
                        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
        }
return xmlHttp;
}
Open in New Window Select All

Answer : ajax passing error, one of the vars is not getting through

Try this in the PHP section that starts with this line:

  if (isset($_GET['ascdesc'])) {

HTH, ~Ray
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:

           
Open in New Window Select All
Random Solutions  
 
programming4us programming4us