Jump to content

Recommended Posts

This one's really got me. I have a 10 pages that all display results from their matching databases. Since they all need the same formatting and paginating I have chosen to insert this code using include(). Now, everything works just fine until you try to follow one of the pagination links. When you do, it sends you to an error page that I had created. The thing is, the error page you go to is in no way linked to the page that you started on! They aren't even in the same directory.

 

The included file is name 'paginate.php' and it looks like this:

 

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.style1{
font-family: "Poor Richard";
font-weight: normal;
font-size: 16pt;
text-align: center;
background-color: #FFFFFF;
}
.style2{
font-family: "Poor Richard";
font-size: 14pt;
background-color: #57A8F9;
text-align: left;
}
.style3{
font-family: "Poor Richard";
font-size: 14pt;
background-color: #57A8F9;
text-align: center;
}
.style4{
font-family: "Poor Richard";
font-size: 18pt;
text-align: center;
}
.style5{
border: 2px solid #FFFFFF;
padding: 2px;
border-spacing: 3px;
width: 100%;
}
.style6{
font-family: "Poor Richard";
font-size: 14pt;
text-align: center;
width: 100%;
}
</style>
</head>

<body>
<?php

echo ("<br>");
echo ("<table class=\"style6\">");
echo ("<tr>");

if($page != 1)
{
$pageprev = $page - 1; 
echo("<td style=\"width: 33%\"><a href=\"".$name."?page=$pageprev\">Previous ".$limit." Listings</a></td>");
}
else
{
echo("<td style=\"width: 33%\">Previous ".$limit." Listings</td>");
}

echo ("<td style=\"width: 33%\">");

$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++)
{
if($i == $page)
	{
	echo($i."  ");
	}
	else
	{
	echo("<a href=\"".$name."?page=$i\">$i</a>  ");
	}
}

if(($totalrows % $limit) != 0)
{
if($i == $page)
	{
	echo($i."  ");
	}
	else
	{
	echo("<a href=\"".$name."?page=$i\">$i</a>  ");
	}
}

echo("</td>");

if(($totalrows - $limit * $page) > 0)
{
$pagenext = $page + 1;
echo("<td style=\"width: 33%\"><a href=\"".$name."?page=$pagenext\">Next ".$limit." Listings</a></td>");
}
else
{
echo("<td style=\"width: 33%\">Next ".$limit." Listings</td>");
}

echo ("</tr></table");

mysql_close($dbh);

?>
</body>
</html>

 

The file that includes paginate.php is called employ.php and it looks like this:

 

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Employment Listings</title>
</head>

<body style="background-color: #0ACCF5; background-image: url('../../../images/InsetBackground.jpg')">

<?php

$db = "bransone_classifieds";
$name = "employment.php";
include("connect.php");
$limit = 10;
$query_count = "SELECT COUNT(Ad_Id) AS Total FROM employment";
$result_count = mysql_query($query_count) or die ("Error in query" . mysql_error());
$fetch_result  = mysql_fetch_assoc($result_count) or die ("Error in query" . mysql_error());
$totalrows = $fetch_result['Total'];

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

$limitvalue = $page * $limit - $limit;
$query  = "SELECT Ad_Id, `Date`, Type_Job FROM employment ORDER BY `Date` DESC, Ad_Id DESC LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());

echo "<p class=\"style4\">Employment Listings</p>";

if(mysql_num_rows($result) == 0)
{
echo ("<p class=\"style1\">There are currently no ads in this category.<\\p>");
}

echo "<table class=\"style5\">
	<tr class=\"style1\">
		<td style=\"width: 10%\">#</td>
		<td>Type of Job</td>
		<td style=\"width: 20%\">Posted On</td>
		<td style=\"width: 15%\">Details</td>
	</tr>";

while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td class=\"style3\">". $row['Ad_Id']."</td>";
echo "<td class=\"style2\">". $row['Type_Job']."</td>";
echo "<td class =\"style3\">". $row['Date']."</td>";
echo "<td class =\"style3\"><a href=\"details.php?id=". $row['Ad_Id']."\">Details</a></td>";
}
echo "</table>";

include("paginate.php");

?>

<br />
<form>
<div class="style6">
	<input type="button" value="Back" onClick="history.go(-1);return true;"></div>
</form>
</body>
</html>

 

I can't see how I'm linking to a page that I haven't linked to, but that's what its doing. Since I have 10 pages that will all use the same code I'd really like to make this work. Any ideas? (sorry this is such a long post)

Link to comment
https://forums.phpfreaks.com/topic/60909-solved-so-confused/
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.