Pear Pager question
| From: | adam bosko | Date: | Mon, 18 Dec 2006 18:08:56 +0000 |
| Subject: | Pear Pager question | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-26150@lists.php.net to get a copy of this message | ||
I have been using this for pagination, but i just realized that the items I used this for on my
Posted queries do not work.
After the 1st page my post is lost and the query is pulling everything.
<?php
require_once "pager/pager.php";
// set up a total & row counters and set them to zero
$total = $row_count = 0;
$rs = mysql_connect ("localhost", "x", "x") or die ('I cannot
connect to the database because: ' . mysql_error());
$rs = mysql_select_db ("x");
$sql = "SELECT * FROM
jobs WHERE 1 ";
if (!empty($_POST['keyword']))
{
$keyword = $_POST['keyword'];
$sql .= " AND keyword LIKE '%$keyword%' ";
}
if (!empty($_POST['city']) )
{
$city = $_POST['city'];
$sql .= " AND city='$city' ";
}
if (!empty($_POST['state'] ) )
{
$state = $_POST['state'];
$sql .= " AND state='$state' ";
}
if (!empty($_POST['catagory']))
{
$catagory = $_POST['catagory'];
$sql .= " AND catagory='$catagory' ";
}
if (mysql_errno != 0)
{
echo "Error in query. Error is: " .mysql_error();
die();
}
$rs = @mysql_query($sql);
if(mysql_num_rows($rs) == 0)
{
echo("No Data match!");
}
?>
<div id="results" >
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<?php
//populate a array data[] with all your found record results
//increment total for each row found
while ($row = mysql_fetch_array($rs))
{
$data[] = $row;
$total++;
}
// set the limit on how many records you wish to display., in my case i just set it to 8
('perPage'=>8)
// pass all these variables to the "pager" classes
$params =
array('itemData'=>$data,'perPage'=>8,'delta'=>8,'append'=>true,'clearIfVoid'=>false,'urlVar'=>'page','useSessions'=>true,'closeSession'=>true,'mode'=>'Jumping');
$pager = Pager::factory($params);
$pagedata = $pager->getPageData();
$links = $pager->getLinks();
// now display your results
foreach ($pagedata as $row)
{
// i changed the way you coloured your rows, this way is easier and better.
$bgcolor1 = "#E0E0E0";
$bgcolor2 = "#FFFFCC";
?>
<tr style="background-color:<?php echo (($row_count % 2) ? $bgcolor1 : $bgcolor2)
?>;">
<td width="30%" align="center"><?php echo
$row['keyword']; ?></td>
<td width="30%" align="center"><?php echo
$row['city']; ?></td>
<td width="10%" align="center"><?php echo
$row['state']; ?></td>
<td width="30%" align="center"><?php echo
$row['catagory']; ?></td>
</tr>
<?php
$row_count++;
}
// last line, is just displays all the page numbers so user can browse each page of 8 records per
page
?>
<tr>
<th colspan="4" height="10px">Page:
<?=$links['all'];?></th>
</tr>
</table>
</div>
THANKS!!!
Adam
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com