I added the $numrows variable (which I overlooked), however I need to figure out how to get the number of rows the database contains after a select is made in the case method, and then display the pagination results accordingly with the proper amount of records that match the criteria. Right now after case selection the pagination displays numbers greater than it should, and not recognizing num of rows from query. Pay close attention to '$numrows = mysql_result($result, 0, 0);' below the case statement.
if (empty($offset)) {
$offset=0;
}
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;
}
$limit = 15;
$query.=" limit $offset, $limit";
$result = mysql_query($query,$db);
$numrows = mysql_result($result, 0, 0);
function listmenu() {
return "<form name=\"form2\" method=\"post\" action=\"home.php?page=manage&action=entries\"><select name=\"sort\" style=\"font-size: 11px; font-weight: bold; color: 000000;\" onchange=\"document.forms['form2'].submit()\">
<option selected>Sort by Category</option>
<option value=\"1\">Sort by Date</option>
<option value=\"2\">Sort by Awareness(Low)</option>
<option value=\"3\">Sort by Awareness(Medium)</option>
<option value=\"4\">Sort by Awareness(High)</option>
<option value=\"5\">Sort by Past Journals</option>
<option value=\"6\">Sort by Recent Journals</option>
</select></form>";
}
print "<table align=\"center\" width=\"95%\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\" class=\"table_border\">\n";
print "<tr><td colspan=\"6\">" . listmenu() . "</td></tr>";
if (mysql_num_rows ($result) == 0) {
print "<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(list($id,$date,$username,$title,$dreamstatus,$entry,$awareness,$pagination) = mysql_fetch_row($result)){
$d = explode("-",$date);
$titletrimmed = substr($title, 0, 30);
$thedate = "$d[2]/$d[1]/$d[0]";
$print = "\n<tr class=\"cells\">\n";
$print .= "<td><li>$date</td><td><b><a href=\"home.php?page=manage&action=modify&entry=$id\">$titletrimmed...</a></b></td>\n";
$print .= "<td>$dreamstatus</td>";
$print .= "<td>$awareness</td>";
$print .= "<td align=\"center\"><a href=\"home.php?page=manage&action=modify&entry=$id\">";
$print .= "Modify</a></td>\n";
$print .= "<td align=\"center\"><a href=\"home.php?page=manage&action=remove&entry=$id\">";
$print .= "Delete</a></td>\n";
$print .= "</tr>\n";
echo $print;
}
}
// NEXT - PREVIOUS LINKS \\
echo "<center>Pages: ";
$pages=intval($numrows/$limit);
if ($numrows%$limit==0) {
$pages++;
if($pages > $limit){
echo"";
}
}
if ($offset != 0) {
$prevoffset=$offset-$limit;
echo "<a class=i href=\"$PHP_SELF?page=manage&action=entries&offset=$prevoffset\"><<</a> \n";
}
if ( $pages != 1 ) {
for ($l=1;$l<=$pages;$l++) {
$newoffset=$limit*($l-1);
if ( ((($offset)/$limit)==($l-1)) ) {
echo "<font class=i>$l</font> | \n";
} else {
echo "<a class=i href=\"$PHP_SELF?page=manage&action=entries&offset=$newoffset\">$l</a> | \n";
}
}
}
if (!((($offset)/$limit)+1==$pages) && $pages!=1) {
$newoffset=$offset+$limit;
echo "<a class=i href=\"$PHP_SELF?page=manage&action=entries&offset=$newoffset\">>></a><p>\n";
}
echo"</table><br></center>";