We help IT Professionals succeed at work.
Get Started

SQL results Pagination/Navigation

488 Views
Last Modified: 2012-09-02
You helped me write the results code ...Thanks Now I need to Navigate the results.

Dreamweavers built-in behaviors do not work as the recordset that delivers the results is not standard. so I need to alter the script somehow to make it work. Presently the first page shows fine but when advancing to the NEXT page I get the error :
Warning: implode() [function.implode]: Invalid arguments passed in /home/jobcast3/public_html/Results/new_index.php on line 3:

 and nothing displays and the back link erases the first page

I have attached the file:

Thanks for Looking

<?php require_once('../Connections/conn_far.php'); ?>
<?php
$_POST['specialties'] = ''.implode(', ', $_POST['specialties']);
$specialties = $_POST['specialties']; //echo "$specialties";

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];
$maxRows_Rs_results = 2;
$pageNum_Rs_results = 0;
if (isset($_GET['pageNum_Rs_results'])) {
  $pageNum_Rs_results = $_GET['pageNum_Rs_results'];
}
$startRow_Rs_results = $pageNum_Rs_results * $maxRows_Rs_results;

mysql_select_db($database_conn_far, $conn_far);
$query_Rs_results = <<<ENDOFSQL
SELECT DISTINCT a_user.user_id, a_user.website, a_user.company_name, a_user.state, a_user.email 
FROM a_user INNER JOIN recruiter_specialties ON a_user.user_id =  recruiter_specialties.member_id AND (a_user.status = 1 OR a_user.status = 5)
ENDOFSQL;

$specvalues = explode(",",$specialties);
$c = 0;
foreach ( $specvalues as $spec ) {
	if ( $c > 0 ) {$query_Rs_results .= " or ";}
	else {$query_Rs_results .= " WHERE ";}
	$query_Rs_results .= "find_in_set(trim('$spec'), replace(recruiter_specialties.spec_id,' ','')) > 0";
	$c++;
}
$query_limit_Rs_results = sprintf("%s LIMIT %d, %d", $query_Rs_results, $startRow_Rs_results, $maxRows_Rs_results);
$Rs_results = mysql_query($query_limit_Rs_results, $conn_far) or die(mysql_error());
$row_Rs_results = mysql_fetch_assoc($Rs_results);

if (isset($_GET['totalRows_Rs_results'])) {
  $totalRows_Rs_results = $_GET['totalRows_Rs_results'];
} else {
  $all_Rs_results = mysql_query($query_Rs_results);
  $totalRows_Rs_results = mysql_num_rows($all_Rs_results);
}
$totalPages_Rs_results = ceil($totalRows_Rs_results/$maxRows_Rs_results)-1;

$queryString_Rs_results = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Rs_results") == false && 
        stristr($param, "totalRows_Rs_results") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Rs_results = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Rs_results = sprintf("&totalRows_Rs_results=%d%s", $totalRows_Rs_results, $queryString_Rs_results);
 ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Find A Recruiter... Search Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content=" recruiter listing, recruiters, headhunters, jobs, careers, employment, employment firms, employment agencies, hiring managers" />
<meta name="Description" content="The ultimate guide for recruiting professionals and job seekers."/>
<link rel="stylesheet" type="text/css" href="../css/stylephp.css" />
<link rel="shortcut icon" href="http://www.jobcast365.com/images/favicon/favicon(2).ico" />
</head>
<body>
<div class="main">
  <div class="top_header">
    <div class="logo"><a href="../index.php"><img src="../images/images/logo.gif" width="443" height="66" border="0" alt="logo" /></a> 
      <!--end logo--></div>
    <div class="menu">
      <?php include('../incfar/menu.inc.php'); ?>
    </div>
    <!-- end menu-->
    <div class="clr"></div>
    <!--end top_header--></div>
  <div class="header_text_bg2">
    <div class="header_text2">
      <h2>Expert Advice</h2>
      <p>Find A Recruiter... Recruiters that work in your chosen specialties 
    </div>
  </div>
  <div class="clr"></div>
</div>
<div class="clr"></div>
<!--end top_header-->

<div class="clr"></div>
<div class="mid_content">
  <div class="mid_content_left">
    <h2>Recruiter Matches<br/>
    </h2>
    <div id="results">
      <?php if ($totalRows_Rs_results > 0) { // Show if recordset not empty ?>
      <h3>Total Recruiters Found:&nbsp;<?php echo $totalRows_Rs_results ?></h3>
      <br /><table border="0">
  <tr>
    <td><?php if ($pageNum_Rs_results > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_Rs_results=%d%s", $currentPage, 0, $queryString_Rs_results); ?>">First</a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_Rs_results > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_Rs_results=%d%s", $currentPage, max(0, $pageNum_Rs_results - 1), $queryString_Rs_results); ?>">Previous</a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_Rs_results < $totalPages_Rs_results) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_Rs_results=%d%s", $currentPage, min($totalPages_Rs_results, $pageNum_Rs_results + 1), $queryString_Rs_results); ?>">Next</a>
        <?php } // Show if not last page ?></td>
    <td><?php if ($pageNum_Rs_results < $totalPages_Rs_results) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_Rs_results=%d%s", $currentPage, $totalPages_Rs_results, $queryString_Rs_results); ?>">Last</a>
        <?php } // Show if not last page ?></td>
  </tr>
</table>
      <table width="95%" id="chosen">
        <THEAD>
          <tr>
            <td>Recruiting Firm</td>
            <td>Corporate Website</td>
          </tr>
        </THEAD>
        <?php do { ?>
          <tr>
            <td><?php echo $row_Rs_results['company_name']; ?></td>
            <td><a href="http://www.<?php echo $row_Rs_results['website']; ?>" target="new"><?php echo $row_Rs_results['website']; ?></a></td>
          </tr>
          <?php } while ($row_Rs_results = mysql_fetch_assoc($Rs_results)); ?>
      </table>
      <?php  } else echo "<h3>No Recruiter  Matches Please Try Again</h3> <br /> <a href='http://www.findarecruiter.com'>Search</a> "
 // Show if recordset not empty ?>
      <br />
      
      <!--end results--> 

Open in new window

Comment
Watch Question
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE