Jump to content

Pagination - Start page help


u214

Recommended Posts

Hey guys. I finally decided to make my pagination webpage with the help of this tutorial: Here

 

I gotta say, it's an awesome, easy to follow tutorial!

--

Ok, so I finished mine. It's working perfectly, but somehow when I'm on the first page, it doesn't show the css styling.. Everything after page 1 works like it should. It's just that start page that keeps bothering me.

 

Here's the page with the bad style: Click

Here's the page with the working style(Anything after this page works perfectyl): Click

 

Here's the code:

	<?php
	include("config.php");
	$result = mysql_query("SELECT COUNT(*) FROM playerinfo", $connect);
	$r = mysql_fetch_row($result);
	$numrows = $r[0];

	$rowsperpage = 10;
	$totalpages = ceil($numrows / $rowsperpage);

	if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
   		$currentpage = (int) $_GET['currentpage'];
	} else {
   		$currentpage = 1;
	}

	if ($currentpage > $totalpages) {
   		$currentpage = $totalpages;
	}
	if ($currentpage < 1) {
   		$currentpage = 1;
	}

	$offset = ($currentpage - 1) * $rowsperpage;

	$sql = "SELECT user, Registered FROM playerinfo LIMIT $offset, $rowsperpage";
	$result = mysql_query($sql);

	echo "<table width=720><tbody>
	<tr>
		<th width=20><span class='table-header'>Player Name:</span></th>
		<th width=20><span class='table-header'>Date Registered:</span></th>
	</tr>";

	while ($list = mysql_fetch_assoc($result)) {
		echo "<tr><td><a href='http://yu-ki-ko.com/fsns/PStats.php?User=".$list['user']."'>".$list['user']."</a></td>";
		echo "<td>".$list['Registered']."</td></tr>";
	}
	echo "</tbody></table>";

	$range = 3;

	if ($currentpage > 1) {

		echo "<div class='pagination'><a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a>";
   		$prevpage = $currentpage - 1;
		echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a>";
	}

	for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
   		if (($x > 0) && ($x <= $totalpages)) {
      		if ($x == $currentpage) {
                echo "<span class='current'>$x</span>";
      		} else {
            echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a>";
      	}
   	}
}
if ($currentpage != $totalpages) {
   		$nextpage = $currentpage + 1;
        echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a>";

   		echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a></div>";
}

?>

(Comments removed to make it more readable)

 

I'm sorry if this is not the correct board to post this, but it has a combination of PHP + HTML.

Link to comment
Share on other sites

I just took a quick glance, but it seems your "pagination" style is only applied if $currentpage is greater than 1

 

if ($currentpage > 1) {
echo "<div class='pagination'><a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a>";

 

that will make it not show when you're on the fist page.

you should have both the div tags (start and end) outside of the conditions, so they're always applied.

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.