/    Sign up×
Community /Pin to ProfileBookmark

Pagenation / Filters

I currently have a php/mysql webspage which displays a job list. This job list have one column for status whcih is either “Raised, In Progress, Completed,On Hold Rejected”

For the status i have a filter at the top so that users can filter out say the completed jobs and just display jobs with a certain status.

The filter works but nor that i have added pagenation there is a slight problem.

I can filter status’ out but the filter only works for the page that i am on at that time, ie if i filter out all of the completed jobs when im on page 2 then it filters page 2 but if i click next it looses the filter and displays all of the jobs.

Any idea’s?

Please Help!

If any1 wants to vies the code pm me

Thanks

Baz

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@scragarApr 22.2005 — I would like to veiw your codes, the odds are your not reading(or writing for reading) in the status from page to page.

I would need to see your code to add it for you, or you could search for yourself(since you will understand it better than me).
Copy linkTweet thisAlerts:
@bazjonesauthorApr 22.2005 — [code=php]
<?php ob_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<HEAD>
<TITLE>PCR Report</TITLE>
<?php require_once("../../menu/ssw_header.shtml"); ?>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>

<meta http-equiv="refresh" content="240">
<script language="JavaScript">
function savescrollpos() {
document.cookie = "scrollpos=" + mybody.scrollTop;
}
function setscrollpos() {

var allCookies = document.cookie;
var pos = allCookies.indexOf("scrollpos=") ;
if (pos != -1) {
var start = pos + 10 ;
var end = allCookies.indexOf(";",start) ;
if (end == -1) end = allCookies.length ;
var value = allCookies.substring(start, end) ;
value =unescape(value) ;
mybody.scrollTop = value ;
}
}
</script>
</HEAD>

<body id="mybody" onScroll="savescrollpos();" onLoad="setscrollpos();" onLoad="placeIt()" onResize="window.location.href=window.location.href">
<?php include "../../include/Return_To_Top.shtml"; ?>
<?php
$normal=0;
$excel_export=1;
if (isset($_REQUEST['excel'])){
$type=$excel_export;
header("Content-Type: application/vnd.ms-excel");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
} else {
$type=$normal;
require_once("../../menu/ssw_menu.shtml");

}

?>

<?php
include "mysql_connect_PCR.php";
$statusselect = isset($_POST['status']) ? $_POST['status'] : array("Raised","In progress","Completed","On Hold","Rejected");

if ($type == 0){
?>
<form action="<?php echo $_SERVER['/PCR/PHP_SELF'];?>" method="post" name="StatusForm">
<table width="76%" border="1" align="center" bordercolor="#000000" bgcolor="#EEFFFF">
<tr>
<td height="32">
<div align="center"><strong>Status Filter :</strong> <strong>Raised:
<input name="status[]" type="checkbox" value="Raised" <?php $checked = @array_search("Raised",$statusselect); if(is_int($checked)) echo "checked";?>>
In progress:
<input name="status[]" type="checkbox" value="In progress" <?php $checked = @array_search("In progress",$statusselect); if(is_int($checked)) echo "checked";?>>
Completed:
<input name="status[]" type="checkbox" value="Completed" <?php $checked = @array_search("Completed",$statusselect); if(is_int($checked)) echo "checked";?>>
On Hold:
<input name="status[]" type="checkbox" value="On Hold" <?php $checked = @array_search("On Hold",$statusselect); if(is_int($checked)) echo "checked";?>>
Rejected:
<input name="status[]" type="checkbox" value="Rejected" <?php $checked = @array_search("Rejected",$statusselect); if(is_int($checked)) echo "checked";?>>
</strong>
<input class="button" type="submit" name="Submit" value="Go">
</div></td>
</tr>
</table>
<div align="center"></div>
</form>
<?php
}
?>
<table width="100%">
<td align="center">
<form name="form2" method="post" action="/quality_management/pcr/pcr_report.php">
<strong>
<input name="Print" type="button" class="button" id="Print3" onClick="window.print()" value="Print Report">
<input name="AddPCR" type="button" class="button" id="AddPCR2" onClick="MM_goToURL('parent','/quality_management/pcr/pcr_form.php');return document.MM_returnValue" value=" Add a PCR ">
<input name="Excel_Export" type="button" class="button" id="Excel_Export" onClick="MM_goToURL('parent','/quality_management/pcr/pcr_report.php?excel=1=');return document.MM_returnValue" value="Excel Export">
</strong>
</form>
</td>
</table>
<table width="100%">
<td align="center">
<form name="form" class="button" action="pcr_search.php" method="get">
<input type="text" name="q">
<input type="submit" name="Submit2" value="Search">
</form>
</td>
</table>

<?php
//---------------------------------------------------
// Set the database query limit for a page
//---------------------------------------------------
$limitPerPage = 60;
$initStartLimit = 0;
if (!isset($_REQUEST['startLimit'])){
$startLimit = $initStartLimit;
} else{
$startLimit = $_REQUEST['startLimit'];
}
$querylimit = ' limit ' . $startLimit . ',' . $limitPerPage;
$nextStartLimit = $startLimit - $limitPerPage;
$previousStartLimit = $startLimit + $limitPerPage;
if (!isset($filter)) { $filter=''; }

if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}

// Define the number of results per page
$max_results = 30;

// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);



// Set query to get PCR data
$query="select PCRID, PCRTitle, RaisedBy, TaskDesc, Status, NextStep, Engineer, date_format(PCRDate,'%d/%m/%Y'), relatedWRA from pcr";
if(count($statusselect) < 5)
{
foreach($statusselect as $key => $value)
{
if($key == 0)
{
$query .= " WHERE status = '".$value."'";
}
else
{
$query .= " OR status = '".$value."'";
}
}
}
$query .= " order by PCRDate DESC, PCRID DESC LIMIT $from, $max_results";


// Execute query
$result = mysql_query ($query) or die (mysql_error());


// Report an error and exit page if the query has failed
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}

// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pcr"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a class='link2' href="".$_SERVER['PHP_SELF']."?page=$prev">&lt;&lt;Prev</a> ";
}

$forend = (($page + 5) < $total_pages) ? ($page + 5) : $total_pages;
$forstart = (($page - 5) > 0) ? ($page -5) : 1;

for ($i = $forstart; $i <= $forend; $i++) {
if(($page) == $i){
echo "$i ";
} else {
echo "<a class='link2' href="".$_SERVER['PHP_SELF']."?page=$i">$i</a>&nbsp;";
}
}

// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a class='link2' href="".$_SERVER['PHP_SELF']."?page=$next">Next&gt;&gt;</a>";
}

// Get number of rows and columns in PCR database
$num_rows = mysql_num_rows($result);
$num_cols = mysql_num_fields($result);

// Output title fields first
echo '<table class="report" cellspacing="0" cellpadding"1" border="1">';
echo '<tr bgcolor=#EEFFFF align=left><th>ID</th><th>Title</th><th>Raised By</th><th>Description</th><th>Status</th><th>Action</th><th>Engineer</th><th>Date</th><th class=columnhead>&nbsp;</th></tr>';

// Loop through each row printing out values
for ( $i=1; $i <= $num_rows; $i++ )
{
$row = mysql_fetch_row($result);
$idindex = 0;
$descindex = 3;
$wraindex = 8;


echo '<tr>';
// Loop through each column apart from relatedWRA
for ( $j=$idindex; $j < $num_cols - 1; $j++ )
{
if ($j==$idindex)
{
echo '<td><a href="pcr_edit.php?pcrid='.$row[$idindex].'" class=link title="Click To Edit PCR">'.$row[$idindex].'</a></td>';
}
else
{ //not first column
if ($row[$j] == NULL)
{ echo '<td>&nbsp;</td>'; }
else
{ if ($j==$descindex && $row[$wraindex] != NULL)
{ echo '<td><b>'.$row[$wraindex].'</b><br>'.$row[$j].'</td>'; }
else
{ echo '<td>'.$row[$j].'</td>'; }
}
} //End else not first column
} // End FOR
if ($type == 0){
echo '<td align=left clas=iconcolumn><a href="/quality_management/pcr/pcr_confirm_delete.php?pcrid='.$row[$idindex].'"><img border=0 src="/images/Trash.gif" title="Click To Delete PCR"></a></td></tr>';
}
}

echo '</table><br>';

// Build Page Number Hyperlinks
echo "<center>Select a Page<br />";

// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a class='link2' href="".$_SERVER['PHP_SELF']."?page=$prev">&lt;&lt;Prev</a> ";
}

$forend = (($page + 5) < $total_pages) ? ($page + 5) : $total_pages;
$forstart = (($page - 5) > 0) ? ($page -5) : 1;

for ($i = $forstart; $i <= $forend; $i++) {
if(($page) == $i){
echo "$i ";
} else {
echo "<a class='link2' href="".$_SERVER['PHP_SELF']."?page=$i">$i</a>&nbsp;";
}
}

// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a class='link2' href="".$_SERVER['PHP_SELF']."?page=$next">Next&gt;&gt;</a>";
}

// Free result set
mysql_free_result($result);

echo $total_results;

// Close connection
mysql_close($link);

?>

<div><hr></div>
<div class="footer">Last Updated: <!-- #BeginDate format:acAm1a -->Fri, April 22, 2005 9:35 AM<!-- #EndDate --></div>
</body>
</html>
<?php ob_end_flush();?>
[/code]
Copy linkTweet thisAlerts:
@scragarApr 22.2005 — could you just change those [code] tags for [code=php] tags? it makes things easier to follow?
×

Success!

Help @bazjones spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...