Jump to content

Pagination Problems


wattsup88

Recommended Posts

Ok i recently completed the expanding on pagination tutorial and it was great ( big thanks to crayon violet ). It worked great when i used on a basic level but when i tried to implement it into one of my search mods it returns "Resource ID #10" for the query... I have tried to search around on the internet (very briefly ) for a page that explains why it is doing that... there were a few sites but i couldn't understand any of them unfortunatley (b/c Im a noob)... here is the code i hope someone can help me understand why and how to fix it...

[code]//calls up the job category selected
if ( is_array( $_POST['category'] ) ) {
foreach ( $_POST['category'] as $value ) {
}
}
//calls up the state selected
if ( is_array( $_POST['stabbrev'] ) ) {
foreach ( $_POST['stabbrev'] as $value1 ) {
}
}

//start up alternating rows
$color2 = "#c8c8c8";
$color1 = "#224477";
$row_count = 0;
//start up alternating rows

//*********pagination variables************
$page = (is_numeric($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] : 1;
$max_results = 4;
$from = (($page * $max_results) - $max_results);
$allowed = array('jbcategory','jbtitle','jbsalary','jbstate');
$sortby = (in_array($_GET['sortby'],$allowed)) ? $_GET['sortby'] : 'jbtitle';

//Query and displayed rows
if ($value=="---Select Job Category---"){
$sql = mysql_query("SELECT jbtitle,jbcategory,jbsalary,jbstate FROM jobs WHERE jbcategory = '$value' OR jbstate = '$value1' ORDER BY $sortby LIMIT $from, $max_results");
}else if ($value1=="---Select State---"){
$sql = mysql_query("SELECT jbtitle,jbcategory,jbsalary,jbstate FROM jobs WHERE jbcategory = '$value' OR jbstate = '$value1' ORDER BY $sortby LIMIT $from, $max_results");
}else{
$sql = mysql_query("SELECT jbtitle,jbcategory,jbsalary,jbstate FROM jobs WHERE jbcategory = '$value' AND jbstate = '$value1' ORDER BY $sortby LIMIT $from, $max_results");
}

echo $sql;



/*$getlist = mysql_query($sql) or die(mysql_error());

//$result = mysql_query("SELECT * FROM jobs ORDER BY jbcategory");

// Figure out the total number of rows in table
$sql = "select count(*) as num from jobs";
$getcount = mysql_query($sql) or die(mysql_error());
$total_results = mysql_result($getcount, 0) or die(mysql_error());

// Figure out the total number of pages we will have
$total_pages = ceil($total_results / $max_results);

// Figure out the current page result numbers
$fr = $from + 1;
$to = $from + mysql_num_rows($getlist);
//**********pagination variables********


//*********Displaying the query***********
//pagination


echo "<table style=\"border-color:990101\" align=\"center\" border=\"0\" bgcolor=\"#990101\" width=\"800\" cellpadding=\"20\">
<tr><td width=\"800\" height=\"10\" bgcolor=\"#990101\" colspan=\"5\"><em><font  size=\"-1\" color=\"#FFFFFF\" face=\"Arial, Helvetica, sans-serif\"><b>Showing $fr to $to of $total_results results</b></font></em></td></tr>";

while ($row = mysql_fetch_array($getlist))
  {
        $jbc = $row['jbcategory'];
        $jbt = $row['jbtitle'];
        $jbs = $row['jbsalary'];
        $jbst = $row['jbstate'];
$jbid = $row['id'];

$row_color = ($row_count % 2) ? $color1 : $color2;

    print "<tr>\n";

echo "<td height=\"10\" bgcolor=\"$row_color\">$jbt</td>";
echo " <td height=\"10\" bgcolor=\"$row_color\">$jbc</td>";
echo "<td height=\"10\" bgcolor=\"$row_color\">$jbs</td>";
echo " <td height=\"10\" bgcolor=\"$row_color\">$jbst</td>";
//echo " <td width=\"45\" height=\"10\" bgcolor=\"$row_color\">".stripslashes($jbid)."</td>";

 
$row_count++;
  }
 
 
//*********Displaying the query***********


 
//*********pagination links start************ 
  echo "<tr><td bgcolor=\"#990101\" align= \"center\" width =\"800\" colspan=\"5\">";
  if($page > 1){
    $prev = ($page - 1);
    echo "<a href='{$_SERVER['PHP_SELF']}?page=1&sortby=$sortby'>First</a> ";
    echo "<a href='{$_SERVER['PHP_SELF']}?page=$prev&sortby=$sortby'>Prev</a> ";
} // end if

// build the links to the 2 previous and 2 next pages
for($i = ($page - 2); $i <= ($page + 2); $i++){
  // only make a link if the prev/next is a valid page number
  if (($i >= 1) && ($i <= $total_pages)) {
    echo ($page == $i) ? "[$i] " : "<a href='{$_SERVER['PHP_SELF']}?page=$i&sortby=$sortby'>$i</a> ";
  } // end if
} // end for
   
// Build Next and Last links. If on last page, we won't make a links
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href='{$_SERVER['PHP_SELF']}?page=$next&sortby=$sortby'>Next</a> ";
    echo "<a href='{$_SERVER['PHP_SELF']}?page=$total_pages&sortby=$sortby'>Last</a>";
} // end if
echo "</tr></td>";
print "</table>\n";
/***** end of pagination ******/
[/code]


Oh and by the way the job category and the job state are being called up correctly...
thanks in advance

-Jacob
Link to comment
https://forums.phpfreaks.com/topic/31629-pagination-problems/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.