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
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