Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

SQL results Pagination/Navigation

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

0
raw888
Asked:
raw888
  • 3
  • 3
1 Solution
 
Chris HarteThaumaturgeCommented:
Invalid argument on an implode usually means you are not using an array. Before line 3 echo the post with the line

echo $_POST['specialties'];
0
 
raw888Author Commented:
The implode works fine until i try to use pagination. the echo was there so I could see if the implode was working properly.
0
 
Ray PaseurCommented:
Not sure what this might be doing to the $_POST array.  I've never seen anybody do that before.

$_POST['specialties'] = ''.implode(', ', $_POST['specialties']);

Suggest you print out the $_POST array with this:

var_dump($_POST);

I would avoid doing any kind of variable assignment in these superglobal environmental variables.  The risks of coding horror are just too great with something like that.  Instead, copy the variable from the POST request like this:

$specialties = implode(', ', $_POST['specialties']);

And, oc course, for this to work, the HTML form that makes this POST method request must create an array in the specialties input control.  You might want to post that HTML form here so we can see how the specialties values are specified.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
raw888Author Commented:
Thanks for looking... The form is a multiple checkbox list that the site user can choose multiple specialties and the form will return all the the members that have those specialties .

<?php require_once('Connections/conn_far.php'); ?>
<?php
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;
}
}

mysql_select_db($database_conn_far, $conn_far);
$query_Rs_specialties = "SELECT spec_id, titles FROM specialties";
$Rs_specialties = mysql_query($query_Rs_specialties, $conn_far) or die(mysql_error());
$row_Rs_specialties = mysql_fetch_assoc($Rs_specialties);
$totalRows_Rs_specialties = mysql_num_rows($Rs_specialties);
 $thisPage="home"; ?>
<!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... Start here</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="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" />
<script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
<script src="CodePeople/ToCheckList/jquery-1.3.2.js" type="text/javascript"></script>
<script src="CodePeople/ToCheckList/toChecklist.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8"></script>
<link href="CodePeople/ToCheckList/toChecklist.css" rel="stylesheet" type="text/css" />
</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>Connections Matter</h2>
      <p>Find A Recruiter... Your search for employment professionals starts here!
      </div>
    </div>
  <div class="clr"></div>
  <div class="header_text">
    <div class="left1">
    <h2>Search For Recruiters <span>NOW!</span><br />
      </h2>
      <div id="search_form">
        <div>
          <form  name="recruiter_search"action="Results/" method="post">
            <span id="codepeople-widget-tochecklist" class="codepeople-tochecklist-widget">
            <select name="specialties" multiple="multiple" id="specialties">
              <?php
do {  
?>
              <option value="<?php echo $row_Rs_specialties['spec_id']?>"><?php echo $row_Rs_specialties['titles']?></option>
              <?php
} while ($row_Rs_specialties = mysql_fetch_assoc($Rs_specialties));
  $rows = mysql_num_rows($Rs_specialties);
  if($rows > 0) {
      mysql_data_seek($Rs_specialties, 0);
	  $row_Rs_specialties = mysql_fetch_assoc($Rs_specialties);
  }
?>
            </select>
            </span>

            <input name="Find Your Recruiter" type="submit" value="Find Your Recruiter" />
          </form>
        </div>
      
      </div><!--end search_form-->
    
      
    </div>
    <div id="movie_comp">
      <div id="movie">
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="353" height="218" id="FlashID" title="Find A Recruiter NOW!">
          <param name="movie" value="flash/header2010.swf" />
          <param name="quality" value="high" />
          <param name="wmode" value="opaque" />
          <param name="swfversion" value="6.0.65.0" />
          <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
          <param name="expressinstall" value="Scripts/expressInstall.swf" />
          <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. --> 
          <!--[if !IE]>-->
          <object type="application/x-shockwave-flash" data="flash/header2010.swf" width="353" height="218">
            <!--<![endif]-->
            <param name="quality" value="high" />
            <param name="wmode" value="opaque" />
            <param name="swfversion" value="6.0.65.0" />
            <param name="expressinstall" value="Scripts/expressInstall.swf" />
            <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
            <div>
              <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
              <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>
            </div>
            <!--[if !IE]>-->
          </object>
          <!--<![endif]-->
        </object>
        <!-- end movie--> 
        
      </div>
    </div>
    <div class="clr"></div>
  </div>
  <div class="clr"></div>
  <div class="mid_content">
    <div class="mid_content_left">
      <h2>Welcome to <span class="grey">Find A Recruiter</span></h2>
      <h3>The site for job seekers &amp; employment professionals to meet.</h3>
      <p>Find A Recruiter provides a portal for Recruiters, Headhunters, Executive Search Consultants, Employment Agencies, Staffing Firms &amp; Search Professionals to showcase their resources to potential clients.</p>
      <br />
      <h2>Featured<span class="grey"> Recruiters</span></h2>
      <img src="images/logo_recruiters/JK_200.jpg" alt="Jacobi Kelly" width="200" height="118" />
      <p><a href="http://www.jkpco.com"><strong>Jacobi Kelly</strong></a><br />
      At JK, the focus is simple... results for our clients. For 30 plus years JK has delivered solutions &amp;  eliminated problems with our world class customer service. Our expertise is in accounting, finance, office administration, engineering, and human resource professions.</p>
      <div class="clr"></div>
      <img src="images/logo_recruiters/restore.jpg" alt="Restoration Personnel Source" width="200" height="118" />
      <p><a href="http://www.restorationpersonnelsource.com" target="_blank"><strong>Restoration Personnel Source</strong></a><br />
      Restoration Personnel Source (RPS) is a nationwide and nationally known specialist firm dedicated to exclusively serving the insurance restoration contractor industry.</p>
      <div class="clr"></div>
      <img src="images/logo_recruiters/hradvantage3.jpg" alt="HR Advantage, Inc." width="200" height="117" />
      <p><a href="http://www.hradvantageinc.net" target="_blank"><strong>HR Advantage, Inc</strong></a><br />
      HR Advantage, Inc. recruits nationally with emphasis in placing professionals in jobs involving human resources, healthcare, telecommunications, government contracting, marketing, high-technology, legal services, public relations, communications, finance, engineering and professional services.</p>
      <div class="clr"></div>
      <p>&nbsp;</p>
      <div class="clr"></div>
      <!--end mid content left--></div>
    <div class="mid_content_right">
      <h2><a href="mailto:ads@badmonkeycommunications.com"> Advertise <span class="grey">With Us</span></a></h2>
      <p class="copy1"><a href="mailto:ads@badmonkeycommunications.com">inquire now</a></p>
      <p></p>
      <div class="clr"></div>
      <p><img src="images/ad_blanks/blue_ad.jpg" width="125" height="125" alt="Advertise with us" /><img src="images/ad_blanks/green_ad.jpg" width="125" height="125" alt="advertise with us" /></p>
      <p><img src="images/ad_blanks/pink_ad.jpg" width="125" height="125" alt="Advertise with us" /><img src="images/ad_blanks/orange_ad.jpg" width="125" height="125" alt="Advertise with us" /></p>
      <p><img src="images/ad_blanks/white_ad.jpg" width="125" height="125" alt="Advertise with Find a Recruiter" /><img src="images/ad_blanks/grey_ad.jpg" width="125" height="125" alt="Advertise with Find A Recruiter" /></p>
    </div>
    <!--end mid content right-->
    <div class="clr"></div>
  </div>
  <div class="clr"></div>
  
  <!--end main--></div>
<div class="footer">
  <?php include('inc/footer.inc.php'); ?>
  <div class="clr"></div>
  <!--</div>-end footer resize-->
  <div class="clr"></div>
  <!--end footer--></div>
<script type="text/javascript">
CodePeople.Widget.ToCheckList("codepeople-widget-tochecklist");//End-CodePeople-Widget;
</script>
</body>
</html>
<?php
mysql_free_result($Rs_specialties);
?>

Open in new window

0
 
Ray PaseurCommented:
See http://www.laprbass.com/RAY_temp_raw888.php

I believe you need bracket notation like this: name="specialties[]"

<?php // RAY_temp_raw888.php
error_reporting(E_ALL);

// SHOW THE INFORMATION FROM THE REQUEST
if (!empty($_POST))
{
    echo "<pre>";
    var_dump($_POST);

    // SHOW HOW TO FIND THE SPECIALTIES
    if (isset($_POST['specialties']))
    {
        foreach ($_POST['specialties'] as $x)
        {
            var_dump($x);
        }
    }
    echo "</pre>";
}

// CREATE THE HTML DOCUMENT
$html = <<<ENDHTML
<h2>Search For Recruiters <span>NOW!</span><br />
      </h2>
      <div id="search_form">
        <div>

<!-- REMOVING THE ACTION= ATTRIBUTE CAUSES THE FORM TO POST TO THIS SCRIPT -->
          <form  name="recruiter_search" method="post">
            <span id="codepeople-widget-tochecklist" class="codepeople-tochecklist-widget">
            <select name="specialties[]" multiple="multiple" id="specialties">

<!-- THIS SIMULATES THE OPTION TAGS THAT ARE CREATED FROM THE QUERY RESULTS SET -->
              <option value="1">Title 1</option>
              <option value="2">Title 2</option>
              <option value="3">Title 3</option>

            </select>
            </span>

            <input name="Find Your Recruiter" type="submit" value="Find Your Recruiter" />
          </form>
        </div>

      </div><!--end search_form-->
ENDHTML;

echo $html;

Open in new window

0
 
raw888Author Commented:
actually solved 2 problems and script is much cleaner...Thanks
0
 
Ray PaseurCommented:
Thanks for the points - it's a great question, ~Ray
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now