[SOLVED] Pagination Page Error (no page numbers displaying)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jonas
Forum Commoner
Posts: 96
Joined: Sun May 23, 2004 9:25 pm

Pagination Page Error (no page numbers displaying)

Post by jonas »

[this error fixed, scroll to most recent post for next]
Last edited by jonas on Fri Jul 16, 2004 4:17 pm, edited 1 time in total.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

A couple things maybe. Looking at this code in Xemacs, I think you're missing a closing bracket. I'd also recommend using heredocs as opposed to print() and escaping all the double quotes. It'll make your life SO much easier not having to escape stuff all the time.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I see a missing brace as well..
jonas
Forum Commoner
Posts: 96
Joined: Sun May 23, 2004 9:25 pm

Post by jonas »

Ok I fixed it. Now I'm trying to get the pagination to work properly.... it only displays the amount it's supposed to which is great but I'm not getting any page numbers to navigate to the next pages.

Test URL: http://forums.bolt3.com/topiclist.php?forumID=117

This is the topics being displayed and there is 12 in the DB.

This is my updated code:

Code: Select all

<?
include("../dbconnection/connect_db.inc.php");
$query = "SELECT * FROM forums where forumID='$forumID'";
$mysql_stuff = mysql_query($query, $mysql_link);
while($roc = mysql_fetch_row($mysql_stuff)){
	$gameID = $roc[1];
	$forum_name = $roc[2];
}
function nextpage($table,$perpage,$start,$page, $query) 
{ 
$start = (int)$start; 
$query = "SELECT count(*) as count FROM $table $query"; 
$result = mysql_query($query); 
$row = mysql_fetch_array($result); 
$numrows = $row[0]; 
// 
// 
$b_link = "<<"; 
if($start > 0) 
{ 
$b_link = "<a href="".$page."&start=".($start - $perpage).""><<</a>"; 
} 
$r .=  "$b_link "; 
// 
$pages = ceil($numrows / $perpage); 
$current_page = ceil($start / $perpage) + 1; 
$link = 1; 
$s = 0; 
for($ba = 1; $ba <= $pages; $ba++) 
{ 
$li = "<a href="$page&start=$s">$link</a> "; 
if($ba == $current_page) 
{ 
$li = "<b>$ba</b> "; 
} 
$page_links .= $li; 
$s = $perpage * $link; 
$link++; 
}}
if (empty($forumID)){
print("
<html>
<head>
<title>Bolt 3 - Error</title>
</head>
<body bgcolor="#DAD6B0" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<link href="css.php" rel="stylesheet" type="text/css">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">"); include('../header.php'); print("</td>
</tr>
<tr>
<td valign="top">
<div align="center">
<table width="778" class="contenttable" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="100%" height="100%" class="contentinside">
<tr>
<td valign="top">
<div align="center">
<br>
<table class="regpart1" cellpadding="0" cellspacing="0">
<tr>
<td>
<div align="center">
<br>
You did not specify a game.<br>
<br>
</div>
</table>
</div>
<br>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>"); include('../footer.php'); print("</td>
</tr>
</table>
</body>
</html>");
} else {
print("
<html>
<head>
<title>Bolt 3 - $forum_name Forum</title>
</head>
<link href="css.php" rel="stylesheet" type="text/css">
<body bgcolor="#DAD6B0" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td valign="top">"); include('../header.php'); print("</td>
	</tr>
	<tr>
	<td>
	<div align="center">
	<table width="778" class="contenttable" cellpadding="0" cellspacing="0">
	<tr>
	<td>
	<div align="center">
	<table width="100%" height="100%" class="contentinside">
	<tr>
	<td>
	<div align="center">
	<table width="768" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td>
		<div align="center">
        	<table width="598" border="0" cellpadding="0" cellspacing="0">
		<tr style='background-color:#6D6B57;'> 
        		<td colspan="3"><div align="center"><font color="#FFFFFF" size="3" face="Verdana, Arial, Helvetica, sans-serif">
				<b>$forum_name</b>
        		</font></div></td>
        	</tr>
		</table>
		</div>
		</td>
	</tr><table width="598" border="1" cellpadding="0" cellspacing="0" bordercolor="#6D6B57">");
$start = (int)$_GET['start']; 
$perpage = 5;//change this to whatever number you like.
$query = mysql_query("SELECT * FROM forum_topics where forumID='$forumID' limit $start, $perpage"); 
while($data = mysql_fetch_array($query)){
	$color = ($roc_bool)?"#9F9C7E":"#A8A58D";
	$color1 = ($roc_bool)?"#A8A58D":"#9F9C7E";
  	$roc_bool = !$roc_bool;
	$memberID = $data[2];
	$topic_title = $data[4];
	$topic_lastpost = $data[5];
	$topic_dateposted = $data[6];
	$topic_timeposted = $data[7];
	print("<tr style='background-color:$color;'><td><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">$topic_title</font></td><td><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">$memberID</font></td><td><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">by: $topic_lastpost</font></td></tr>");
} 
echo "<tr>"."<td>".nextpage("forum_topics",$perpage,$start,$_SERVER['PHP_SELF'], "where forumID='$forumID'")."</td>"."</tr>"; 
	print("</table>
		<tr>
		<td>
		<div align="center">
		<table width="598" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="20" border="0" bgcolor="#6D6B57"><div align="left"><img src="http://www.bolt3.com/siteimages/tf-left.gif"></div></td>
			<td bgcolor="#6D6B57"><div align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><a class="header" href="gameinfo.php?gameID=$gameID">Info</a> | <a class="header" href="codes.php?gameID=$gameID">Codes/Secrets</a> | <a class="header" href="hints.php?gameID=$gameID">Hints/Glitches</a> | <a class="header" href="faqs.php?gameID=$gameID">FAQs/Walkthroughs</a> | <a class="header" href="http://forums.bolt3.com/topiclist.php?forumID=$forumID">Forum</a></font></div></td>
			<td width="20" border="0" bgcolor="#6D6B57"><div align="right"><img src="http://www.bolt3.com/siteimages/tf-right.gif"></div></td>
		</tr>
		</table>
		</div>
		</td>
	</tr>
	</table>
	</div>
	</td>
	</tr>
	</table>
	</div>
	</td>
	</tr>
	</table>
	</td>
	</tr>
	</table>
	</div>
	</td>
	</tr>
	<tr>
		<td>"); include('../footer.php'); print("</td>
	</tr>
</table>
</body>
</html>");
}
?>

How do I get the page numbers to show up
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

Code: Select all

<?php 
function nextpage($table,$perpage,$start,$page, $query) 
{ 
$start = (int)$start; 
$query = "SELECT count(*) as count FROM $table $query"; 
$result = mysql_query($query); 
$row = mysql_fetch_array($result); 
$numrows = $row[0]; 
$b_link = "<<"; 
if($start > 0) 
{ 
$b_link = "<a href="".$page."&start=".($start - $perpage).""><<</a>"; 
} 
$r .=  "$b_link "; 
$pages = ceil($numrows / $perpage); 
$current_page = ceil($start / $perpage) + 1; 
$link = 1; 
$s = 0; 
for($ba = 1; $ba <= $pages; $ba++) 
{ 
$li = "<a href="$page&start=$s">$link</a> "; 
if($ba == $current_page) 
{ 
$li = "<b>$ba</b> "; 
} 
$page_links .= $li; 
$s = $perpage * $link; 
$link++; 
} 
$f_link = ">>"; 
if($numrows > ($start + $perpage)) 
{ 
$f_link = " <a href="".$page."&start=".($start + $perpage)."">>></a>"; 
} 
$r .= "$page_links $f_link<br />Displaying Page ".($current_page)." of $pages<br /></b></font>\n\n\n"; 
if($numrows != 0) 
{ 
return $r; 
} 
} 
?>
jonas
Forum Commoner
Posts: 96
Joined: Sun May 23, 2004 9:25 pm

Post by jonas »

Cool. I replaced my code with that.
http://forums.bolt3.com/topiclist.php?forumID=117

The only thing is when I click page 2 or 3 or the next page arrows it says page cannot be displayed.

I need to submit the forumID to the next page to get it to display properly. How would I do this properly?

I need it to go to http://forums.bolt3.com/topiclist.php?f ... 17&start=5 (or whatever)
and right now its just going to http://forums.bolt3.com/topiclist.php&start=5
Thanks (this should be the last problem :))
Last edited by jonas on Fri Jul 16, 2004 6:48 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$_GET['forumID'] maybe ;)
jonas
Forum Commoner
Posts: 96
Joined: Sun May 23, 2004 9:25 pm

Post by jonas »

I mean how do I put that in the links..... so the numbers and arrows go to the right place.
jonas
Forum Commoner
Posts: 96
Joined: Sun May 23, 2004 9:25 pm

Post by jonas »

Got it, thanks dudes.
Post Reply