Hi All,
I have a site with information displayed. with radio buttons the user can select after what criteria the information has to be sorted. I store his 'criteria' in a variable, i. e. $sort and then I run a query on my table with :
ORDER BY '$sort'
This works fine. In order to display the sorted information only 20 results at a time I use the Pagination script I found here on the forum. It works at first site, but when I click the link to the next 20 results, the information is not sorted anymore..
Any idea why not??
A.
$sort = $_POST['sort'];
//display sorted information
function displayTasks($strSQL)
{
echo "\n<table border=1>\n<tr>" .
"\n\t<th>ID</th>" .
"\n\t<th>Due Date</th>" .
"\n\t<th>Employee</th>" .
"\n\t<th>Company</th>" .
"\n\t<th>Priority</th>" .
"\n\t<th>Task</th>\n</th>" .
"\n\t<th>File</th>\n</tr>";
// Fetch each of the query rows
while ($row = @ mysql_fetch_array($strSQL))
{
// Print one row of results
echo "\n<tr>" .
"\n\t<td>" . $row["task1_id"] . "</td>" .
"\n\t<td>" . $row["due_date"] . "</td>" .
"\n\t<td>" . $row["employee_name"] . "</td>" .
"\n\t<td>" . $row["company"] . "</td>" .
"\n\t<td>" . $row["priority"] . "</td>" .
"\n\t<td>" . $row["task"] . "</td>" .
"\n\t<td>" . $row["link"] . "</td>" .
"\n</tr>";
} // end while loop body
// Finish the <table>
echo "\n</table>";
// } // end if $rowsFound body
} // end of function
###############################################
// Connect To MySQL Server
@mysql_connect($hostName, $username, $password) or die("Couldn't Connect to Database");
// Select Database
@mysql_select_db($databaseName) or die("Couldn't Select Database");
// set number of results to display per page
$pagelimit = "20";
// run query
$strSQL = mysql_query("SELECT * FROM task1"); //ORDER BY '$sort'
// count number of matches
$totalrows = mysql_num_rows($strSQL);
// determine how many pages there will be by using ceil() and dividing total rows by pagelimit
$pagenums = ceil ($totalrows/$pagelimit);
// if no value for page, page = 1
if ($page==''){
$page='1';
}
// create a start value
$start = ($page-1) * $pagelimit;
// blank matches found
echo "<b>" . $totalrows . " matches found</b><br>\n";
// Showing Results 1 to 5
$starting_no = $start + 1;
if ($totalrows - $start < $pagelimit) {
$end_count = $totalrows;
} elseif ($totalrows - $start >= $pagelimit) {
$end_count = $start + $pagelimit;
}
echo "Results $starting_no to $end_count shown.<br>\n";
// create dynamic next, previous, and page links
if ($totalrows - $end_count > $pagelimit) {
$var2 = $pagelimit;
} elseif ($totalrows - $end_count <= $pagelimit) {
$var2 = $totalrows - $end_count;
}
$space = " ";
// previous link
if ($page>1) {
echo "« <a href='sort_view.php?page=".($page-1)."' class=main>Previous" . $space . $pagelimit . "</a>" . $space . $space . "";
}
// dynamic page number links
for ($i=1; $i<=$pagenums; $i++) {
if ($i!=$page) {
echo " <a href='sort_view.php?page=$i' class=main>$i</a>";
}
else {
echo " <b class='red'>$i</b>";
}
}
// next link
if ($page<$pagenums) {
echo "" . $space . $space . $space . $space . " <a href='sort_view.php?page=".($page+1)."' class=main>Next " . $var2 . "</a> »";
}
// Query with LIMIT function
$strSQL = mysql_query("SELECT * FROM task1 ORDER BY '$sort' LIMIT $start,$pagelimit");
//show the query
displayTasks($strSQL);