MasterACE14 Posted March 28, 2009 Share Posted March 28, 2009 hey all, I got a page pagination script off the net, works fine on its own, I have integrated it into my current site and it doesn't want to show anything results from the database. However when I run the query in phpMyAdmin it works fine. pagination script: <?php /** * PHPSense Pagination Class * * PHP tutorials and scripts * * @package PHPSense * @author Jatinder Singh Thind * @copyright Copyright (c) 2006, Jatinder Singh Thind * @link http://www.phpsense.com */ // ------------------------------------------------------------------------ class PS_Pagination { var $php_self; var $rows_per_page; //Number of records to display per page var $total_rows; //Total number of rows returned by the query var $links_per_page; //Number of links to display per page var $sql; var $debug = false; var $conn; var $page; var $max_pages; var $offset; /** * Constructor * * @param resource $connection Mysql connection link * @param string $sql SQL query to paginate. Example : SELECT * FROM users * @param integer $rows_per_page Number of records to display per page. Defaults to 10 * @param integer $links_per_page Number of links to display per page. Defaults to 5 */ function PS_Pagination($connection, $sql, $rows_per_page = 50, $links_per_page = 5) { $this->conn = $connection; $this->sql = $sql; $this->rows_per_page = $rows_per_page; $this->links_per_page = $links_per_page; $this->php_self = htmlspecialchars($_SERVER['PHP_SELF']); if(isset($_GET['page'])) { $this->page = intval($_GET['page']); } } /** * Executes the SQL query and initializes internal variables * * @access public * @return resource */ function paginate() { if(!$this->conn) { if($this->debug) echo "MySQL connection missing<br />"; return false; } $all_rs = @mysql_query($this->sql); if(!$all_rs) { if($this->debug) echo "SQL query failed. Check your query.<br />"; return false; } $this->total_rows = mysql_num_rows($all_rs); @mysql_close($all_rs); $this->max_pages = ceil($this->total_rows/$this->rows_per_page); //Check the page value just in case someone is trying to input an aribitrary value if($this->page > $this->max_pages || $this->page <= 0) { $this->page = 1; } //Calculate Offset $this->offset = $this->rows_per_page * ($this->page-1); //Fetch the required result set $rs = @mysql_query($this->sql." LIMIT {$this->offset}, {$this->rows_per_page}"); if(!$rs) { if($this->debug) echo "Pagination query failed. Check your query.<br />"; return false; } return $rs; } /** * Display the link to the first page * * @access public * @param string $tag Text string to be displayed as the link. Defaults to 'First' * @return string */ function renderFirst($tag='First') { if($this->page == 1) { return $tag; } else { return '<a href="'.$this->php_self.'?page=1">'.$tag.'</a>'; } } /** * Display the link to the last page * * @access public * @param string $tag Text string to be displayed as the link. Defaults to 'Last' * @return string */ function renderLast($tag='Last') { if($this->page == $this->max_pages) { return $tag; } else { return '<a href="'.$this->php_self.'?page='.$this->max_pages.'">'.$tag.'</a>'; } } /** * Display the next link * * @access public * @param string $tag Text string to be displayed as the link. Defaults to '>>' * @return string */ function renderNext($tag=' >>') { if($this->page < $this->max_pages) { return '<a href="'.$this->php_self.'?page='.($this->page+1).'">'.$tag.'</a>'; } else { return $tag; } } /** * Display the previous link * * @access public * @param string $tag Text string to be displayed as the link. Defaults to '<<' * @return string */ function renderPrev($tag='<<') { if($this->page > 1) { return '<a href="'.$this->php_self.'?page='.($this->page-1).'">'.$tag.'</a>'; } else { return $tag; } } /** * Display the page links * * @access public * @return string */ function renderNav() { for($i=1;$i<=$this->max_pages;$i+=$this->links_per_page) { if($this->page >= $i) { $start = $i; } } if($this->max_pages > $this->links_per_page) { $end = $start+$this->links_per_page; if($end > $this->max_pages) $end = $this->max_pages+1; } else { $end = $this->max_pages; } $links = ''; for( $i=$start ; $i<$end ; $i++) { if($i == $this->page) { $links .= " $i "; } else { $links .= ' <a href="'.$this->php_self.'?page='.$i.'">'.$i.'</a> '; } } return $links; } /** * Display full pagination navigation * * @access public * @return string */ function renderFullNav() { return $this->renderFirst().' '.$this->renderPrev().' '.$this->renderNav().' '.$this->renderNext().' '.$this->renderLast(); } /** * Set debug mode * * @access public * @param bool $debug Set to TRUE to enable debug messages * @return void */ function setDebug($debug) { $this->debug = $debug; } } ?> script that doesn't want to show any results: <?php include "start.php"; //Include the PS_Pagination class include('ps_pagination.php'); player_session(); include "top.php"; error_reporting(E_ERROR); // grab current players stats from UserDetails $userrow = get_table($_SESSION['isLogined']); /* $query = mysql_query("SELECT * FROM `UserDetails` INNER JOIN `Ranks` ON `UserDetails`.`ID`=`Ranks`.`userID` WHERE `UserDetails`.`active`='1' ORDER BY `Ranks`.`rank` ASC") or die(mysql_error()." -can not select players!"); */ ?> <table class="table_lines" cellspacing="0" cellpadding="6" width="100%" border="0"> <tbody> <tr> <th>Name</th> <th>Rank</th> <th colspan="2">Army Size</th> <th>Treasury</th> <th>Action</th> </tr> <?php /* if ($cgi['search']) { $strS = $cgi['search']; if ($cgi['search_type'] == 's') { $strS .= "%"; } elseif ($cgi['search_type'] == 'c') { $strS = "%" . $strS . "%"; } else { $strS = "%" . $strS; } $users = searchRanksUsersList($cgi['page'], $strS); } */ if(1 == 2) { } else { $pag = 'SELECT `ID`, `userName`, `trainedAttackSold`, `trainedAttackMerc`, `trainedDefSold`, `trainedDefMerc`, `untrainedSold`, `untrainedMerc`, `spies`, `race`, `gold` FROM `UserDetails`'; //Create a PS_Pagination object $pager = new PS_Pagination($conn,$pag); //The paginate() function returns a mysql //result set for the current page $rs = $pager->paginate(); } $x = 1; $y = 1; $i = 0; while($users = mysql_fetch_object($rs)) { $row = get_table($users[$i]->ID); if ($row['active'] == "1" || $row['active'] == "2") { $in_alliance = $row['Alliance']; if ($in_alliance != "") { $arow_sql = "SELECT * FROM Alliance WHERE Alliance_ID='$in_alliance' LIMIT 1"; $arow_query = mysql_query($arow_sql) or die("Error Retrieving Alliance Information <br /> Error: " . mysql_error() . " Error Number: " . mysql_errno()); $arow2 = mysql_fetch_assoc($arow_query); $arows = $row['Alliance_Status']; $arowa = $arow2['Alliance_Alias']; $arown = $arow2['Alliance_Name']; if ($arows == "2") { $alias[$x] = "<font color=\"green\">" . $arowa . "</font> "; $alias2[$y] = "<font color=\"green\">" . $arown . "</font> "; } elseif ($arows == "4") { $alias[$x] = "<font color=\"red\">" . $arowa . "</font> "; $alias2[$y] = "<font color=\"red\">" . $arown . "</font> "; } elseif ($arows == "3") { $alias[$x] = "<font color=\"orange\">" . $arowa . "</font> "; $alias2[$y] = "<font color=\"orange\">" . $arown . "</font> "; } else { $alias[$x] = "<font color=\"blue\">" . $arowa . "</font> "; $alias2[$y] = "<font color=\"blue\">" . $arown . "</font> "; } } if ($row['active'] == 2) { $alias[$x] = "<b><font color=\"red\">[bANNED]</font></b> "; $alias2[$y] = "<font color=\"red\">Attack without turns.</font> "; } $mycovert = getCovert($user->ID); $theircovert = getCovert($users[$i]->ID); ?> <tr> <td> <a href="stats.php?id=<?php echo $users[$i]->ID; ?>"> <?php echo $alias[$x] . " " . $users[$i]->userName . "<br /><font size=\"1\"><em>" . $alias2[$y] . "</em></font>" ?></a> </td> <td style="PADDING-RIGHT: 20px" align="right"> <?php echo numecho($users[$i]->Rank); ?> </td> <td align="right"> <?php if ($mycovert < $theircovert) { echo "???"; } else { numecho(getTotalFightingForce($users[$i]->ID)); } ?> </td> <td align="left"> <?php echo $conf["race"][$users[$i]->race]["name"]; ?> </td> <td style="PADDING-RIGHT: 20px" align="right"> <?php if ($mycovert < $theircovert) { echo "???"; } else { numecho($users[$i]->gold); } ?> Copper </td> <td align="center"> <?php if ($row['ID'] == $userrow['ID']) { echo " "; } elseif ($row['Alliance'] != "" && $row['Alliance'] == $userrow['Alliance']) { echo "<font color=\"blue\">ALLIANCE</font>"; } elseif ($row['protection'] > "0") { echo "<font color=\"green\">PROTECTED</font>"; } else { echo "<a href=\"attack.php?id=" . $users[$i]->ID . "\">Attack</a>"; } ?> </td> </tr> <?php $x++; $y++; } $i++; } ?> <tr> <td> </td> <td align="middle" colspan="4"> <?php //Display the navigation echo $pager->renderFullNav(); ?> </td> <td> </td> </tr> </tbody> </table> <br /><br /> <form action="battlefield.php" method="get"> <table class="table_lines" cellspacing="0" cellpadding="6" width="550" align="center" border="0"> <tbody> <tr> <th align="middle" colspan="2">Search</th></tr> <tr> <td align="right">Jump to page:</td> <td align="left"> <input maxlength="5" size="5" name="page" /> <input type="submit" value="Go" /> </td></tr> <tr> <td align="right">Search by username:</td> <td align="left"> <select name="search_type"> <option value="s" selected label="starts with">starts with</option> <option value="c" label="contains">contains</option> <option value="e" label="ends with">ends with</option> </select> <input name="search" /> <input type="submit" value="Go" /> </form> </td></tr></tbody></table> <br /> <?php include("bottom.php"); ?> Any help is greatly appreciated! Regards, ACE Link to comment https://forums.phpfreaks.com/topic/151483-page-pagination-not-working/ Share on other sites More sharing options...
MasterACE14 Posted March 28, 2009 Author Share Posted March 28, 2009 bump Link to comment https://forums.phpfreaks.com/topic/151483-page-pagination-not-working/#findComment-795722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.