Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting table generated by ajax

Status
Not open for further replies.

sskarth

Programmer
Jul 21, 2010
5
US
Hi,

I am using a javascript called sorttable.js available at for sorting a table.

The issue is the table is generate via an AJAX script. When I generate the table via ajax script, the sort feature seems to be not present. I found some comment regarding this at by Hugo Pineda but still I am not able to figure the issue.

Below is the code called by AJAX. Any help will be greatly appreciated.

<?php
// database connection

$from = $_GET['from'];
$to = $_GET['to'];

$from = mysql_real_escape_string($from);
$to = mysql_real_escape_string($to);

$query1 = "SELECT MMM_DD FROM mdnumbers WHERE BINARY MMM_DD='$from';";
$res1 = mysql_query($query1);
$query2 = "SELECT MMM_DD FROM mdnumbers WHERE BINARY MMM_DD='$to';";
$res2 = mysql_query($query2);

if (mysql_num_rows($res1)>0 && mysql_num_rows($res2)>0)
{
$fvalue = mysql_query("SELECT MDvalue FROM mdnumbers WHERE MMM_DD = '$from'");
$fromvalue1= mysql_result($fvalue, 0);

$tvalue = mysql_query("SELECT MDvalue FROM mdnumbers WHERE MMM_DD = '$to'");
$tovalue1= mysql_result($tvalue, 0);

$result = mysql_query("SELECT * FROM annotations WHERE DayOfYear BETWEEN $fromvalue1 AND $tovalue1 ORDER BY DayOfYear");

if (mysql_num_rows($result)>0)
{
echo '<html xmlns=" lang="en-US">' . "\n";
echo '<head>';

echo '<script type="text/javascript" src="sorttable.js"></script>';
echo '<script type="text/javascript">
sorttable.makeSortable($ajax_table);
</script>';
echo'</head>';

echo '<body>' . "\n";

echo '<table id="ajax_table" class="sortable" width = "98%" align="center">';

echo '<tr>';
echo '<th>Day</th>';
echo '<th>Year</th>';
echo '<th>Category</th>';
echo '<th>Annotation</th>';
echo '<th>Link</th>';
echo '</tr>';

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['MMM_DD'] . "</td>";
echo "<td>" . $row['Year'] . "</td>";
echo "<td>" . $row['Category'] . "</td>";
echo "<td>" . $row['Annotation'] . "</td>";
echo "<td><a href=" .$row['Link']. ">" .$row['Link']. "</a> </td>";
echo "</tr>";
}

echo "</table>";

echo "</body>\n";
echo "</html>\n";
}
else
{
echo "No Annotations to display for the selected period";

}
}
else
{
echo "Please enter FROM and TO values in proper format. Examples: Jan-23, Nov-14, Sep-15.";
}
?>

Thank you all in advance for your help.
-SK
 
What is held in the variable "$ajax_table"? This is the second example of posting server-side code to a client-side form asking for client-side help I've seen in the last 3 posts I've read! How about showing real client-side code?

That aside, have you tried moving the call to "makeSortable" to the end of your code, so it is called AFTER the table is rendered? Perhaps it's failing because the table isn't present when then call is made, which this would fix.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top