View Single Post
Old 09-15-2012, 01:15 AM   PM User | #1
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 849
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
Exclamation Slight issues with my Ajax call

Hi, I have an Ajax script which I have modified to suit my needs...nearly.

I have 2 links:
Code:
<a href="#" name="ASC" onmouseup="showUser('ASC')">ASC</a>|
<a href="#" name="DESC" onmouseup="showUser('DESC')">DESC</a>
as you can see when they are clicked they go into this ajax function:
Code:
<script type="text/javascript">
   function showUser(order)
 {
 if (order=="")
   {
   document.getElementById("content").innerHTML=xmlhttp.responseText;
   } 
 if (window.XMLHttpRequest)
   {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
   }
 else
   {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
 xmlhttp.onreadystatechange=function()
   {
   if (xmlhttp.readyState==4 && xmlhttp.status==200)
     {
     document.getElementById("content").innerHTML = xmlhttp.responseText;
     }
   }
 xmlhttp.open("GET","sort.php?q="+order,true);
 xmlhttp.send();
 }
 </script>
This goes into my db when it is called and re-arranges the list by what they choose, either ascending or descending. If the function hasn't run, it displays the list by member number (this is set in my sort.php).

Here is my sort.php:
PHP Code:
<?php
require("connectdb.php");

if(empty(
$_GET['q'])){

  
$sql mysql_query("SELECT * FROM members");
  
  echo 
"<table id='members_table' name='members_table'>
        <tr>
           <th>Member No.</th>
           <th>Username</th>
           <th>Join Date</th> 
        </tr>"
;

  while(
$row mysql_fetch_array($sql)){
    echo 
"<tr>";
    echo 
"<td>" $row['id'] . "</td>";
    echo 
"<td>" $row['username'] . "</td>";
    echo 
"<td>" $row['join_date'] . "</td>";
    echo 
"</tr>";
  }
  echo 
"</table>";

  
}
else{
   
$q $_GET['q'];
   
$sqlmysql_query("SELECT * FROM members ORDER BY username {$q}");

   echo 
"<table id='members_table' name='members_table'>
         <tr>
            <th>Member No.</th>
            <th>Username</th>
            <th>Join Date</th> 
         </tr>"
;

   while(
$row mysql_fetch_array($sql)){
      echo 
"<tr>";
      echo 
"<td>" $row['id'] . "</td>";
      echo 
"<td>" $row['username'] . "</td>";
      echo 
"<td>" $row['join_date'] . "</td>";
      echo 
"</tr>";
   }
   echo 
"</table>";
}

mysql_close($con);
?>
Problem is, when I click on either the ASC or DESC links, they go into the correct order, but both of the links disappear.

Can anyone help me to fix this problem please!?

Thanks you in advance.

Regards,

LC.

Last edited by LearningCoder; 09-15-2012 at 03:03 PM..
LearningCoder is offline   Reply With Quote