Jump to content

Pages help again...


nezbo

Recommended Posts

hi all

 

I have nearly finished the code and i cant seem to get it to display the <prev 1 2 3 4 etc.. on the pages after the first page.

 

e.g.

 

I click on next and it works fine but there is nothing there to click on the next page(s)... there is 5 pages on the first page that can be clicked on but nothing on the rest of the pages, all the data is there but no <prev 1 2 3 4 5 next>

 

Any ideas ?

 

$display = 10;

if (isset($_GET['np']))
{
	$num_pages = $_GET['np'];
}
else
{
	$query =  "SELECT COUNT(*) FROM job WHERE Completed='Yes' ORDER BY JobID DESC" or die("oh dear" . mysql_error());
	$result = mysql_query($query);
	$row2 = mysql_fetch_array($result, MYSQL_NUM);
	$num_records = $row2[0];
}

if ($num_records > $display) 
{
	$num_pages = ceil ($num_records/$display);
}
else
{
	$num_pages = 1;
}

if (isset($_GET["s"]))
{
	$start = $_GET["s"];
}
else
{
	$start = 0;
}

$completedJobs = "SELECT * FROM job WHERE Completed='Yes' ORDER BY JobID DESC LIMIT $start, $display" or die("crap!!!" . mysql_error());

$result2 = mysql_query($completedJobs);



echo "<table border=1 align = center width=90%><tr>";
echo "<tr><td colspan=10 align=center><h2>Check Jobs</h2><tr><td>";
echo "
<tr bgcolor = #acacac>
<td>Call ID
<td>PCIU Number
<td>Reported By
<td>Passed To
<td>Job Completed
<td>Problem Discription
<td>Outcome
<td>Date
<td>Time
<td>Site Name";

$bgcolour = "#ffffff";
while ($row = mysql_fetch_array($result2, MYSQL_ASSOC))
{

	if ($bgcolour == "#ffffff")
	{	
		echo "<tr bgcolor = #ffffff>
			<td><a href=editJob.php?job_identifier=$row[JobID] >$row[JobID] </a></td>
			<td align=left>$row[PCIUno]</td>
			<td align=left>$row[RepBy]</td>
			<td align=left>$row[PassedTo]</td>
			<td align=left>$row[Completed]</td>
			<td align=left>$row[Problem]</td>
			<td align=left>$row[OutCome]</td>
			<td align=left>$row[callDate]</td>
			<td align=left>$row[callTime]</td> 
			<td align=left>$row[site]</td>
		</tr>";
		$bgcolour = "#ececec";
	}
	else
	{	
		echo "<tr bgcolor = #ececec>
			<td><a href=editJob.php?job_identifier=$row[JobID] >$row[JobID] </a></td>
			<td align=left>$row[PCIUno]</td>
			<td align=left>$row[RepBy]</td>
			<td align=left>$row[PassedTo]</td>
			<td align=left>$row[Completed]</td>
			<td align=left>$row[Problem]</td>
			<td align=left>$row[OutCome]</td>
			<td align=left>$row[callDate]</td>
			<td align=left>$row[callTime]</td> 
			<td align=left>$row[site]</td>
		</tr>";
		$bgcolour = "#ffffff";
	}
}
if ($num_pages > 1)
{
	echo "<br /><p>";
	$current_page = ($start/$display) + 1;

	if ($current_page != 1) 
		{
			echo "<a href=\"checkCompletedJobs.php?s=" . ($start - $display) . "&np=" . $num_pages . "\">Previous</a> ";
		}

	for ($i = 1; $i <= $num_pages; $i++)
		{
			if($i != $current_page)
				{
						echo "<a href=\"checkCompletedJobs.php?s=" . ($display * ($i - 1)) . "&np=" . $num_pages . "\">" . $i . "</a> ";
				}
				else
				{
					echo $i . "";
				}
		}
		if ($current_page != $num_pages)
			{
				echo "<a href=\"checkCompletedJobs.php?s=" . ($start + $display) . "&np=" . $num_pages . "\">Next</a>";
			}

}

Link to comment
Share on other sites

ok well i will just go ahead and post the code and how to use it:

 

<?php
function pagination($h,$get,$page,$z) {
$g = ceil($h/$z);
$d = 0;
$u = 0;
$o = 0;
if($g>1) {
	while($d!=$g) {
		$d++;
		if($get) {
			if($get==$g){
				$c = $get - 4;
				if($c!=0) {
					$o = 1;
				}
				if($o==0) {
					$d = $get - 3;
					$o = 1;
				}
				if($d==$get) {
					echo("<b>[$d]</b>");
					echo(" ");
				}else{
					$c = $get - 4;
					if($c!=0) {
						echo("<a href=\"$page&pg=$d\">$d</a>");
						echo(" ");
					}else{
						if($u==0) {
							echo("<a href=\"$page&pg=1\">1</a>");
							echo(" ... ");
							$u = 1;
						}else{
							echo("<a href=\"$page&pg=$d\">$d</a>");
							echo(" ");
						}
					}
				}
			}else{
				if($d==$get) {
					echo("<b>[$d]</b>");
					echo(" ");
				}else{
					if($get==1) {
						if($d<4) {
							echo("<a href=\"$page&pg=$d\">$d</a>");
							echo(" ");
						}else{
							echo("... <a href=\"$page&pg=$g\">$g</a>");
							$d = $g;
						}
					}else{
						$a = $get - 4;
						$b = $get + 2;
						if($a>0) {
							if($d==$get) {
								echo("<b>[$d]</b>");
								echo(" ");
							}else{
								if($u==0) {
									echo("<a href=\"$page&pg=1\">1</a>");
									echo(" ... ");
									$u = 1;
								}else{
									if($o==0) {
										$d = $get - 2;
										$o = 1;
									}
									if($get+3==$d) {
										if($b<$g-1) {
											echo(" ... ");
											echo("<a href=\"$page&pg=$g\">$g</a>");
											$d = $g;
										}else{
											echo("<a href=\"$page&pg=$d\">$d</a>");
											echo(" ");
										}
									}else{
										echo("<a href=\"$page&pg=$d\">$d</a>");
										echo(" ");
									}
								}
							}
						}else{
							if($get+3==$d) {
								if($b<$g-1) {
									echo(" ... ");
									echo("<a href=\"$page&pg=$g\">$g</a>");
									$d = $g;
								}else{
									echo("<a href=\"$page&pg=$d\">$d</a>");
									echo(" ");
								}
							}else{
								echo("<a href=\"$page&pg=$d\">$d</a>");
								echo(" ");
							}
						}
					}
				}
			}
		}else{
			if($d==1) {
				echo("<b>[$d]</b>");
				echo(" ");
			}else{
				if($d<4) {
					echo("<a href=\"$page&pg=$d\">$d</a>");
					echo(" ");
				}else{
					echo("... <a href=\"$page&pg=$g\">$g</a>");
					$d = $g;
				}
			}
		}
	}
}else{
	echo("<b>[1]</b>");
}
}
?>

 

this is quite a big function but it is very effective.

 

to use it you must have this at the begining of the page or require_once from a functions.php page

 

<?php
pagination($h,$_GET['pg'],"yourpage.php?",5);
?>

ok the $h has to be how many rows you have exaple(this isnt good coding just a ex.) while("SELECT * FROM info") { $h++; }

the $_GET['pg'] is the page number you are on i would keep this system on a GET cmd of pg

the page is the page which can include other GET cmds like action=view you would enter yourpage.php?action=view and so on

the 5 is the intraval like how many you want on a page this was an extra addition to the code so that i could use it on multiple sites.

 

If you would like any more info on this please just ask PM me maybe

Link to comment
Share on other sites

the code i sent you is only making the main body of the script i am including hedders and footers etc...

 

so the code is the table and the numbers etc...

 

i dont see how the code you gave us can make that links code

the no problem= isnt in your code at all....

Link to comment
Share on other sites

remove np=7 from your link, you calculate from s in which page you are

 

i see in your page that you don't use no problem (it is no problem, i think)

name with space is not regular from form field, convert space to '_'

Link to comment
Share on other sites

im easly confused and that has done the trick  :'(

 

 

 

 

remove no problem=7 from your link, you calculate from s in which page you are

 

i see in your page that you don't use no problem (it is no problem, i think)

name with space is not regular from form field, convert space to '_'

Link to comment
Share on other sites

;D

 

It seams to be working now yippee.

 

i thought you was just bullying my with the "no Problem" thing but it turns out i was just confused and you are all genouses :)

 

Cheers

 

all of the pages work without the no problem=blah :D except they have a 7 infront of the Previous

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.