I'm trying to display the proper page numbers after selecting a drop down menu option. The drop down menu uses a case method to supply the correct WHERE statements and therefore adjusts the $total_rows value.
I am having difficulties getting the page numbering to synch with this. Anyone have any suggestions..? Thanks
//Modify Entries
if($action == "entries"){
include("manage/modify.php");
$query = "Select * FROM $table WHERE username = '".$_SESSION['username']."'";
switch($_POST['sort']) {
case 1:
$query.=" ORDER by date DESC";
break;
case 2:
$query.=" AND awareness = 'Low' ORDER by awareness";
break;
case 3:
$query.=" AND awareness = 'Medium' ORDER by awareness";
break;
case 4:
$query.=" AND awareness = 'High' ORDER by awareness";
break;
case 5:
$query.=" AND dreamstatus = 'Past' ORDER by dreamstatus";
break;
case 6:
$query.=" AND dreamstatus = 'Recent' ORDER by dreamstatus";
break;
}
echo "<table align=\"center\" width=\"95%\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\" class=\"table_border\">\n<tr><td colspan=\"6\>
<form name=\"form2\" method=\"post\" action=\"myjournal.php?page=manage&action=entries\"><select name=\"sort\" style=\"font-size: 11px; font-weight: bold; color: 000000;\" onchange=\"document.forms['form2'].submit()\">";
if($_POST['sort'] != 1 or 2 or 3 or 4 or 5 or 6) {
echo "<option selected value=\"1\">Sort by Category</option>";
} else {
echo "<option>Sort by Category</option>";
}
if($_POST['sort'] == 1) {
echo "<option selected value=\"1\">Sort by Date</option>";
} else {
echo "<option value=\"1\">Sort by Date</option>";
}
if ($_POST['sort'] == 2) {
echo "<option selected value=\"2\">Sort by Awareness(Low)</option>";
} else {
echo "<option value=\"2\">Sort by Awareness(Low)</option>";
}
if($_POST['sort'] == 3) {
echo "<option selected value=\"3\">Sort by Awareness(Medium)</option>";
} else {
echo "<option value=\"3\">Sort by Awareness(Medium)</option>";
}
if($_POST['sort'] == 4) {
echo "<option selected value=\"4\">Sort by Awareness(High)</option>";
} else {
echo "<option value=\"4\">Sort by Awareness(High)</option>";
}
if($_POST['sort'] == 5) {
echo "<option selected value=\"5\">Sort by Past Journals</option>";
} else {
echo "<option value=\"5\">Sort by Past Journals</option>";
}
if($_POST['sort'] == 6) {
echo "<option selected value=\"6\">Sort by Recent Journals</option>";
} else {
echo "<option value=\"6\">Sort by Recent Journals</option>";
}
echo "</select></form></td></tr>";
$limit = 15;
$result = mysql_query($query,$db); //total results
$total_rows = mysql_num_rows($result);
if (mysql_num_rows($result) == 0) {
echo "<tr class=\"cells\"><td colspan=\"6\"><font color=red>No entries found. Please select another search criteria.</font></td></tr>";
} else {
$p .= "<tr class=\"header_cell\">";
$p .= "<td>Date</td><td>Title</td><td>Past or Recent</td><td>Awareness</td><td>Modify</td><td>Delete</td></tr>\n";
echo $p;
while ($row = mysql_fetch_array ($result)){
$d = explode("-",$row['date']);
$thedate = "$d[2]/$d[1]/$d[0]";
$echo = "\n<tr class=\"cells\">\n";
$echo .= "<td><li>".$row['date']."</td><td><b><a href=\"myjournal.php?page=manage&action=modify&entry=".$row['id']."\">".substr($row['title'], 0, 30)."...</a></b></td>\n";
$echo .= "<td>".$row['dreamstatus']."</td>";
$echo .= "<td>".$row['awareness']."</td>";
$echo .= "<td align=\"center\"><a href=\"myjournal.php?page=manage&action=modify&entry=".$row['id']."\">";
$echo .= "Modify</a></td>\n";
$echo .= "<td align=\"center\"><a href=\"myjournal.php?page=manage&action=remove&entry=".$row['id']."\">";
$echo .= "Delete</a></td>\n";
$echo .= "</tr>\n";
echo $echo;
}
}
echo "</table><br></center>";
// NEXT - PREVIOUS LINKS \\
echo "<center>";
// next determine if offset has been passed to script, if not use 0
if (empty($offset)) {
$offset=1;
}
if ($offset==1) { // bypass PREV link if offset is 0
$prevoffset=$offset-20;
print "<a href=\"$PHP_SELF?page=manage&action=entries&offset=$prevoffset\">PREV</a> \n";
}
// calculate number of pages needing links
$pages=intval($total_rows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($total_rows%$limit) {
// has remainder so add one page
$pages++;
}
for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
print "<a href=\"$PHP_SELF?page=manage&action=entries&offset=$newoffset\">$i</a> \n";
}
// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$newoffset=$offset+$limit;
print "<a href=\"$PHP_SELF?page=manage&action=entries&offset=$newoffset\">NEXT</a><p>\n";
echo "</center>";
}
}
// END DEFAULT PANEL VIEW