Paginator script Malfunction
Posted: Thu Jun 17, 2010 1:02 pm
Greetings again, PHP Technorati. Again, I grace your doorstep with another pressing issue in php. I found this great php paginator script.
But I cant assimilate it into my MySQL query script. One problem which I am observing is the blending of 2 cascading style sheets. One CSS
is on the actual search results page and the other in a separate file which is linked to from the head section of the results page.
Here is the code for the search results page:
Here is the paginator script:
Ok, the search results are functioning meaning it will yield what is queried. But there is no evidence of pagination . Also, because of a blending of the style sheets, resulting in other page element that are enclosed which is also perplexing me. Please show me the error of my ways.
Thanks in advance,
Batoe
But I cant assimilate it into my MySQL query script. One problem which I am observing is the blending of 2 cascading style sheets. One CSS
is on the actual search results page and the other in a separate file which is linked to from the head section of the results page.
Here is the code for the search results page:
Code: Select all
<?php
include 'sessions.php';
if($login->authorised() == false) {
header("Location: mail_login.php");
}
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>Search Results!</TITLE>
<link rel="icon" href="images/logo1.png" type="image/png">
<link href="images/style.css" rel="stylesheet" type="text/css">
<style type="text/css">
.paginate {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
}
a.paginate {
border: 1px solid #FF8C00;
padding: 2px 6px 2px 6px;
text-decoration: none;
color: #FF8C00;
}
a.paginate:hover {
background-color: #FF8C00;
color: #FFF;
text-decoration: underline;
}
a.current {
border: 1px solid #FF8C00;
font: bold .7em Arial,Helvetica,sans-serif;
padding: 2px 6px 2px 6px;
cursor: default;
background:#FF8C00;
color: #FFF;
text-decoration: none;
}
span.inactive {
border: 1px solid #999;
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
padding: 2px 6px 2px 6px;
color: #999;
cursor: default;
}
table {
margin: 8px;
}
th {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
background: #666;
color: #FFF;
padding: 2px 6px;
border-collapse: separate;
border: 1px solid #000;
}
td {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
border: 1px solid #DDD;
}
</style>
<script>
function hilite(elem)
{
elem.style.background = '#FFC';
}
function lowlite(elem)
{
elem.style.background = '';
}
</script>
</HEAD>
<BODY>
<STYLE type="text/css">
HTML
{scrollbar-face-color: #edf5f7; scrollbar-shadow-color: #25587E;
scrollbar-highlight-color: #25587E; scrollbar-3dlight-color: #25587E;
scrollbar-darkshadow-color: #25587E; scrollbar-track-color: #FFFFFF;
scrollbar-arrow-color: #FBB917}
</STYLE>
<table border="0" width="1000">
<tr>
<td><table border="0" width="800" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top" ><? include 'holiday_logo.php' ?><BR><table border="0" cellspacing="0" cellpadding="0" height="25" width="775" background="images/menu.jpg">
<tr>
<td align="left"style="PADDING-LEFT: 10px"><span class="menu">Welcome: <?php echo $_SESSION['boss_login']['company'];?></span></td>
<td width="4" height="24" align="left" valign="top"><img src="images/menu_separater.gif" width="3" height="24"></td>
<td align="CENTER"><span class="menus"><a href="hr_area.php" class="menus" style="text-decoration:none;">Home</a></span></td>
<td width="4" height="24" align="left" valign="top"><img src="images/menu_separater.gif" width="3" height="24"></td>
<td align="CENTER"><span class="menu" style="text-decoration:none;">Search</span></td>
<td width="4" height="24" align="left" valign="top"><img src="images/menu_separater.gif" width="3" height="24"></td>
<td align="CENTER" ><span class="menus"><a href="my_saves.php" class="menus" style="text-decoration:none;">My Candidates</a></span></td>
<td width="4" height="24" align="left" valign="top"><img src="images/menu_separater.gif" width="3" height="24"></td>
<td align="CENTER" ><span class="menus"><a href="login4.php?logout=true"class="menus" style="text-decoration:none;">logout</a></span> </td>
</tr></table><br>
<span class="style4"> <?php
$b = time();
$hour = date("g",$b);
$m = date ("A", $b);
if ($m == "PM")
{
if ($hour == 12)
{
echo "Good Afternoon!";
}
elseif ($hour < 5)
{
echo "Good Afternoon!";
}
elseif ($hour > 5)
{
echo "Good Evening!";
}
}
elseif ($m == "AM")
{
if ($hour == 12)
{
echo "Good Morning!";
}
elseif ($hour < 12)
{
echo "Good Morning!";
}
}
?>
<? print(Date("l F d, Y")); ?><br></span><? require 'banner_exch_2.php';?> <a href="http://resu-pic.jobamatic.com/a/jbb/post-job" class="orange"><img src="images/job_post.jpg" width="236" height="44" border="0" alt="POST A JOB!"></a></td>
<td align="left" rowspan="2"style="PADDING-TOP: 37px"><img src="images/graphic world.jpg" width="201" height="261" border="0"></td>
</tr>
</table></td>
</tr></table><br>
<table border="0" width="980">
<tr>
<td align="left" valign="top" width="970" >
<div align="left"><fieldset> <legend><span class="style1">Advanced Candidate Search </span></legend><span class="style1"><form method="POST" action="results.php">I need a <SELECT name=category>
<option></option>
<option>Accounting/Finance/Insurance</option>
<option>Administrative/Clerical</option>
<option>Advertising/Marketing/Public Relations</option>
<option>Aerospace/Aviation/Defense</option>
<option>Agriculture, Forestry, & Fishing</option>
<option>Airlines</option>
<option>Architectural Services</option>
<option>Arts, Entertainment, and Media</option>
<option>Automotive/Motor Vehicle/Parts</option>
<option>Banking</option>
<option>Banking/Real Estate/Mortgage Professionals</option>
<option>Biotech/R&D/Science</option>
<option>Biotechnology and Pharmaceutical</option>
<option>Building and Grounds Maintenance</option>
<option>Building Construction/Skilled Trades</option>
<option>Business Opportunity/Investment Required</option>
<option>Business/Strategic Management</option>
<option>Career Fairs</option>
<option>Computer Services</option>
<option>Computers, Hardware</option>
<option>Computers, Software</option>
<option>Consulting Services</option>
<option>Consumer Products</option>
<option>Creative/Design</option>
<option>Customer Support/Client Care</option>
<option>Editorial/Writing</option>
<option>Education/Training</option>
<option>Electronics</option>
<option>Employment Placement Agencies</option>
<option>Energy/Utilities</option>
<option>Engineering</option>
<option>Environmental Services</option>
<option>Finance/Economics</option>
<option>Financial Services</option>
<option>Food Services/Hospitality</option>
<option>Government and Policy</option>
<option>Healthcare - Business Office & Finance</option>
<option>Healthcare - CNAs/Aides/MAs/Home Health</option>
<option>Healthcare - Laboratory/Pathology Services</option>
<option>Healthcare - LPNs & LVNs</option>
<option>Healthcare - Medical & Dental Practitioners</option>
<option>Healthcare - Medical Records, Health IT & Informatics</option>
<option>Healthcare - Optical</option>
<option>Healthcare - Other</option>
<option>Healthcare - Pharmacy</option>
<option>Healthcare - Radiology/Imaging</option>
<option>Healthcare - RNs and Nurse Management</option>
<option>Healthcare - Social Services/Mental Health</option>
<option>Healthcare - Support Services</option>
<option>Healthcare - Therapy/Rehab Services</option>
<option>Hospitality/Tourism</option>
<option>Human Resources</option>
<option>Installation/Maintenance/Repair</option>
<option>Insurance</option>
<option>Internet/E-Commerce</option>
<option>IT/Software Development</option>
<option>Legal</option>
<option>Logistics/Transportation</option>
<option>Manufacturing/Production/Operations</option>
<option>Marketing/Product</option>
<option>Medical/Health</option>
<option>Military</option>
<option>Nonprofit</option>
<option>Operations Management</option>
<option>Other</option>
<option>Personal Care and Service</option>
<option>Printing/Editing/Writing</option>
<option>Project/Program Management</option>
<option>Purchasing</option>
<option>Quality Assurance/Safety</option>
<option>Research & Development</option>
<option>Retail/Wholesale</option>
<option>Sales - Account Management</option>
<option>Sales - Telemarketing</option>
<option>Sales - Work at Home/Commission Only</option>
<option>Sales/Retail/Business Development</option>
<option>Security/Protective Services</option>
<option>Sports and Recreation/Fitness</option>
<option>Telecommunications</option>
<option>Textiles</option>
<option>Transportation and Warehousing</option>
<option>Veterinary Services</option>
<option>Waste Management Services</option></SELECT>Professional with <SELECT name=years_exp>
<option></option>
<OPTION >0 to 1 year</OPTION>
<OPTION >1 to 3 years</OPTION>
<OPTION >4 to 6 years</OPTION>
<OPTION >7 to 10 years</OPTION>
<OPTION >11 to 15 years</OPTION>
<OPTION >more than 15 years</OPTION>
</SELECT>Experience, at least a <p><SELECT name=degree>
<option></option>
<OPTION >H.S. Diploma/GED</OPTION>
<OPTION >Technical School</OPTION>
<OPTION >Some College</OPTION>
<OPTION >College Degree</OPTION>
<OPTION >Some Grad School</OPTION>
<OPTION >Masters Degree/Law/MD</OPTION>
<OPTION >Doctorate/PhD</OPTION>
</SELECT>Level of Education, willing to work<SELECT name=work_time>
<option></option>
<OPTION >Full Time</OPTION>
<OPTION >Part Time</OPTION>
<OPTION >Temporary</OPTION>
<OPTION >Temp to Perm</OPTION>
<OPTION >Contract</OPTION>
<OPTION >No preference</OPTION>
</SELECT>, and available <SELECT name=available>
<option></option>
<option>Immediately</option>
<option>1 to 3 weeks</option>
<option>1 to 3 months</option>
<option>6 to 8 months</option>
<option>I will make arrangements, later.</option></SELECT>.
<p><center><input type=hidden name=submitted value=true>
<input type="image" SRC="images/search_bt.jpg" HEIGHT="20" WIDTH="66" ALT="Search Candidates"></center></form><P></span>
</FIELDSET></div>
</td>
</tr>
<tr colspan="2">
<td width="980"><fieldset><legend><span class="style12">Search Results</span></legend>
<P><table border="0" width="960" bgcolor="#FDE7A2" cellspacing="0" cellpadding="0">
<tr><td colspan="6"><span class="style2">Found : <b><?php echo $count_1; ?></b> Results.</span><p></td></tr>
<tr>
<td colspan="6"><table border="0" cellspacing="0" cellpadding="0" height="25" width="970" background="images/menu_bg.gif">
<tr>
<td style="padding-left: 18px;" width="120"><span class="menu">Candidate ID #:</span></td>
<td width="4" height="24" align="left" valign="top"><img src="images/menu_separater.gif" width="3" height="24"></td>
<td width="260" height="24" align="left" valign="middle"><span class="menu">Job Category:</span></td>
<td width="4" height="24" align="left" valign="top"><img src="images/menu_separater.gif" width="3" height="24"></td>
<td width="140" height="24" align="left" valign="middle"><span class="menu">Experience:</span></td>
<td width="4" height="24" align="left" valign="top"><img src="images/menu_separater.gif" width="3" height="24"></td>
<td width="140" height="24" align="left" valign="middle"><span class="menu">Education:</span></td>
<td width="4" height="24" align="left" valign="top"><img src="images/menu_separater.gif" width="3" height="24"></td>
<td width="140" height="24" align="left" valign="middle"><span class="menu">Availabilty:</span></td>
<td width="4" height="24" align="left" valign="top"><img src="images/menu_separater.gif" width="3" height="24"></td>
<td width="80" height="24" align="left" valign="middle"><span class="menu">View:</span></td>
</tr>
</table></td>
</tr>
<?php
if (isset($_POST['submitted']))
{
$category=$_POST['category'];
$years_exp=$_POST['years_exp'];
$degree=$_POST['degree'];
$work_time=$_POST['work_time'];
$availabile=$_POST['available'];
require 'paginate.php';
require 'open_js_db.php';
$data_1 = mysql_query("SELECT COUNT(*) FROM js_profile WHERE category ='$category'") or die(mysql_error());
$result = mysql_query($data_1);
$count_1 = '0';
//Edit $data to be your query
$querystring = mysql_query("SELECT * FROM js_profile WHERE category ='$category'") or die(mysql_error());
$rows = mysql_num_rows($querystring);
$check = '0';
//This is where you display your query results
while($info = mysql_fetch_array( $querystring ))
{
if ($check % 2 == 0)
{
$text .= '<tr width="970">';
}
else
{
$text .= '<tr bgcolor="#F89858">';
}
$text .= '<td width="144" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$info['candidateID'].'</span></td>';
$text .= '<td width="264" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$info['category'].'</span></td>';
$text .= '<td width="144" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$info['years_exp'].'</span></td>';
$text .= '<td width="144" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$info['degree'].'</span></td>';
$text .= '<td width="144" height="24" align="left" valign="middle" style="padding-left: 15px;"><span class="style1">'.$info['available'].'</span></td>';
$text .= '<td width="80" align="center" valign="middle" style="padding-left: 15px;"><span class="style1"><form action="get_res.php" method="POST"><input type="hidden" name="candidateID" value="'.$info['candidateID'].'"><input type=hidden name=category value="'. $info['category'].'">
<input type=hidden name=years_exp value="'.$info['years_exp'].'">
<input type=hidden name=degree value="'.$info['degree'].'">
<input type=hidden name=work_time value="'.$info['work_time'].'">
<input type=hidden name=available value="'.$info['available'].'">
<input type="submit" value="VIEW"></form></span></td>';
$text .= '</tr>';
$check ++;
}
if($check == 0)
{
$text .= '<tr width = "970">';
$text .= '<td align="center" width="100%"><span class="style1"><b>No candidates found!</b></span></td>';
$text .= '</tr>';
}
echo $text;
echo "<tr width =970 ><td align=left width=100% ><span class=style12><p>Found:<b>".$check."</b> candidates!</span></td></tr>";
}
?>
</table><p></fieldset></td></tr><tr><td>
<table border="0" cellspacing="0" cellpadding="0" height="25" width="975" background="images/menu.jpg">
<tr>
<td align="left"style="PADDING-LEFT: 10px"><span class="style11">All Rights Reserved © 2007 Resu-Pic.Com® Registered Trademark.</span></td>
<td width="4" height="24" align="left" valign="top"><img src="images/menu_separater.gif" width="3" height="24"></td>
<td align="CENTER"><span class="style1"><a href="privacy.html" class="style1" style="text-decoration:none;">Privacy Policy</a></span> </td>
<td width="4" height="24" align="left" valign="top"><img src="images/menu_separater.gif" width="3" height="24"></td>
<td align="CENTER"><a href="privacy.html" class="style1" style="text-decoration:none;">About Us</a></span> </td>
<td width="4" height="24" align="left" valign="top"><img src="images/menu_separater.gif" width="3" height="24"></td>
<td align="CENTER"><a href="contact.html" class="style1" style="text-decoration:none;">Contact Us</a></span> </td>
</tr></table></td></tr></table>
</BODY>
</HTML>
Code: Select all
<?php
class Paginator{
var $items_per_page;
var $items_total;
var $current_page;
var $num_pages;
var $mid_range;
var $low;
var $high;
var $limit;
var $return;
var $default_ipp = 25;
var $querystring;
function Paginator()
{
$this->current_page = 1;
$this->mid_range = 7;
$this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp;
}
function paginate()
{
if($_GET['ipp'] == 'All')
{
$this->num_pages = ceil($this->items_total/$this->default_ipp);
$this->items_per_page = $this->default_ipp;
}
else
{
if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
$this->num_pages = ceil($this->items_total/$this->items_per_page);
}
$this->current_page = (int) $_GET['page']; // must be numeric > 0
if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1;
if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages;
$prev_page = $this->current_page-1;
$next_page = $this->current_page+1;
if($_GET)
{
$args = explode("&",$_SERVER['QUERY_STRING']);
foreach($args as $arg)
{
$keyval = explode("=",$arg);
if($keyval[0] != "page" And $keyval[0] != "ipp") $this->querystring .= "&" . $arg;
}
}
if($_POST)
{
foreach($_POST as $key=>$val)
{
if($key != "page" And $key != "ipp") $this->querystring .= "&$key=$val";
}
}
if($this->num_pages > 10)
{
$this->return = ($this->current_page != 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$prev_page&ipp=$this->items_per_page$this->querystring\">« Previous</a> ":"<span class=\"inactive\" href=\"#\">« Previous</span> ";
$this->start_range = $this->current_page - floor($this->mid_range/2);
$this->end_range = $this->current_page + floor($this->mid_range/2);
if($this->start_range <= 0)
{
$this->end_range += abs($this->start_range)+1;
$this->start_range = 1;
}
if($this->end_range > $this->num_pages)
{
$this->start_range -= $this->end_range-$this->num_pages;
$this->end_range = $this->num_pages;
}
$this->range = range($this->start_range,$this->end_range);
for($i=1;$i<=$this->num_pages;$i++)
{
if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... ";
// loop through all pages. if first, last, or in range, display
if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
{
$this->return .= ($i == $this->current_page And $_GET['page'] != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
}
if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... ";
}
$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET['page'] != 'All')) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$next_page&ipp=$this->items_per_page$this->querystring\">Next »</a>\n":"<span class=\"inactive\" href=\"#\">» Next</span>\n";
$this->return .= ($_GET['page'] == 'All') ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">All</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n";
}
else
{
for($i=1;$i<=$this->num_pages;$i++)
{
$this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
}
$this->return .= "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n";
}
$this->low = ($this->current_page-1) * $this->items_per_page;
$this->high = ($_GET['ipp'] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1;
$this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
}
function display_items_per_page()
{
$items = '';
$ipp_array = array(10,25,50,100,'All');
foreach($ipp_array as $ipp_opt) $items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n";
return "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page=1&ipp='+this[this.selectedIndex].value+'$this->querystring';return false\">$items</select>\n";
}
function display_jump_menu()
{
for($i=1;$i<=$this->num_pages;$i++)
{
$option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n";
}
return "<span class=\"paginate\">Page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page$this->querystring';return false\">$option</select>\n";
}
function display_pages()
{
return $this->return;
}
}
?>Ok, the search results are functioning meaning it will yield what is queried. But there is no evidence of pagination . Also, because of a blending of the style sheets, resulting in other page element that are enclosed which is also perplexing me. Please show me the error of my ways.
Thanks in advance,
Batoe