Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Another sniplet of code needed: PHP linking

Custom Title Activated
Loyal Member
Joined
Mar 9, 2004
Messages
2,425
Reaction score
2
ok this time i need some code tht will link pages

ok lemme try n explain, i know how to set it in php to only display a certain amount of records in the database on a page but i want to know once i have reached the ammount i have set, to be able to link to the rest of the records

i hope i explained it right ><

here is an image of wht im trying to say

sutsurikeru - Another sniplet of code needed: PHP linking - RaGEZONE Forums
 
Banned
Banned
Joined
Apr 30, 2003
Messages
348
Reaction score
1
easy, give me a minute

PHP:
/* Made by nightwolfz */
/* This is a simplified version of my code, feel free to edit */

    $page = $HTTP_GET_VARS['page'];
    $per_page = 50;
    if (empty($page)){
    for ($i=1;$i <=9999999;$i++){
    if (($per_page*$i)>$rank||($per_page*($i+1))<$rank) {
    $page=$i;
    break;
    ******
    
    $sql_text = ('SELECT * FROM user_info ORDER BY level DESC'); 
    $result_count = @mysql_query($sql_text); 
    $totalrows = @mysql_num_rows($result_count);
    if (empty($page)) @$page = 1; 
    $limitvalue = @$page * $per_page - ($per_page); // Ex: (2 * 25) - 25 = 25 <- data starts at 25 
    $sql_text = $sql_text . ' LIMIT ' . $limitvalue.', ' . $per_page;

db($sql_text);


/* ur stuff/code here*/

/* ur stuff/code here if ya want*/


/* This will show the pages, < 1,2,3 > */

echo "<table><td class='lowlight'>Pages: ";
        //previous 
        if ($page != 1) { 
        $pageprev = $page - 1; 
        echo '<a class="brown" href="'.URL_PREFIX.'game.php?loc=list&page='.$pageprev.'"><<</a>'; 
        **
        //active pages 
        $numofpages = $totalrows / $per_page; 
        for($i = 1; $i <= $numofpages; $i++) { 
        if ($i == $page) echo ' '.$i;
        else echo ' <a class="brown" href="'.URL_PREFIX.'game.php?loc=list&page='.$i.'">'.$i.'</a>'; 
        ** 
        //check for remaining rows
        if (($totalrows % $per_page) != 0) { 
        if ($i == $page) echo ' '.$i;
        else echo ' <a class="brown" href="'.URL_PREFIX.'game.php?loc=list&page='.$i.'">'.$i.'</a>';
        ** 
        //next 
        if( ($totalrows - ($per_page * $page)) > 0) { 
        $pagenext = $page + 1; 
        echo ' <a class="brown" href="'.URL_PREFIX.'game.php?loc=list&page='.$pagenext.'">>></a>'; 
        ** else //no next or add unavailable option
				echo "</td></table>";
    mysql_free_result($query); //paranoid cleaner
	print_footer();
	exit;

(btw it looks like dan installed an anti-double post hack lol)
 
Last edited:
TitansTech / SCFMT
Joined
Mar 23, 2004
Messages
129
Reaction score
388
My simple contribution.....

PHP:
<?
$rowsPerPage = 20;
$pageNum = 1;
if(isset($_GET['page'])){
    $pageNum = $_GET['page'];
**
$offset = ($pageNum - 1) * $rowsPerPage;
$query   = "SELECT COUNT(*) AS numrows FROM baneados";
$result  = mysql_query($query) or die('Error, query failed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);
echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">
     <tr>
    <th width=\"22%\" scope=\"col\" class=\"celdaamarilla\"><strong>Usuario o Personaje</strong></th>
    <th width=\"41%\" scope=\"col\" class=\"celdaamarilla\"><strong>Razon del Ban</strong></th>
    <th width=\"18%\" scope=\"col\" class=\"celdaamarilla\"><strong>Responsable</strong></th>
    <th width=\"19%\" scope=\"col\" class=\"celdaamarilla\"><strong>Tiempo del ban</strong></th>
  </tr>";
$self = "/?action=banneds";
if ($pageNum > 1)
{
    $page = $pageNum - 1;
    $prev = " <a href=\"$self&page=$page\">[Previo]</a> ";

    $first = " <a href=\"$self&page=1\">[Primera pagina]</a> ";
**
else
{
    $prev  = ' [Previo] ';
    $first = ' [Primera pagina] ';
**
if ($pageNum < $maxPage)
{
    $page = $pageNum + 1;
    $next = " <a href=\"$self&page=$page\">[Siguiente]</a> ";

    $last = " <a href=\"$self&page=$maxPage\">[Ultima pagina]</a> ";
**
echo "<tr><th colspan=\"4\" scope=\"col\">";
echo $first . $prev . " Mostrando pagina <strong>$pageNum</strong> de <strong>$maxPage</strong> paginas " . $next . $last;
echo "</th></tr>";
    $result = mysql_query("SELECT *
      FROM baneados
      WHERE id
      ORDER BY `id` DESC
      LIMIT $offset, $rowsPerPage",
    $link);
while($row = mysql_fetch_array($result)) {
echo "
<tr>
    <th scope=\"row\" class=\"celdaamarilla\"><div align=\"center\"><strong>".$row["usuario"]."</strong></div></th>
    <td><div align=\"center\" class=\"tablapublicidad\">".$row["razon"]."</div></td>
    <td><div align=\"center\" class=\"tablapublicidad\">".$row["responsable"]."</div></td>
    <td><div align=\"center\" class=\"tablapublicidad\">".$row["tiempo"]."</div></td>
  </tr>";
 **
echo "</table>";
?>
 
Custom Title Activated
Loyal Member
Joined
Mar 9, 2004
Messages
2,425
Reaction score
2
thanks guys ill impliment ur code n post the outcome :)

edit: i had some problems whilst puttin the code in ><

here is my current page i want to impliment it on

PHP:
<b>All Anime Records</b><br>

Here is a list of all current records in the Database. Just click the link to your desired anime and it will give you information on it!<BR><BR>

<table border="0" cellspacing="1" width="520">
 <tr>
      <td width="186" align="center"><b>Anime</b></td>
      <td width="139" align="center"><b>Date Added</b></td>
      <td width="173" align="center"><b>Added by</b></td>
    </tr>




<? 
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","like ill post this","heh");
	
//select which database you want to edit
mysql_select_db("sutsweblog"); 

//If cmd is not hit
if(!isset($cmd)) 
{
   //~~~~~~~~~~~~~~~~~~~~
   $result = mysql_query("select * from anime_db ORDER BY anime_name ASC"); 
   
   //~~~~
   while($r=mysql_fetch_array($result)) 
   { 
      //moo
      $anime_name=$r["anime_name"];
      $id=$r["id"];
$date=$r["date"];
$added_by=$r["added_by"];
     
echo "<tr>
      <td width=\"186\" align=\"center\"><a href='series.php?id=$id'>$anime_name</a></td>
      <td width=\"139\" align=\"center\">$date</td>
      <td width=\"173\" align=\"center\">$added_by</td>
    </tr>";

    **
**
?></table><BR><BR>

this gives

when i tryed puttin ur script in i was gettin unexpected "*" errors n

so if 1 of ya can fit ur code into the above ill be very greatful
 
Last edited:
Custom Title Activated
Loyal Member
Joined
Feb 27, 2004
Messages
1,378
Reaction score
50
btw to to make pages.. like 1 2 3 etc..

u of the best ways is to make a array of all contents and manage it and split it. and use session cookies or even $_GET variables to navigate thru them
 
Custom Title Activated
Loyal Member
Joined
Mar 9, 2004
Messages
2,425
Reaction score
2
john_d said:
btw to to make pages.. like 1 2 3 etc..

u of the best ways is to make a array of all contents and manage it and split it. and use session cookies or even $_GET variables to navigate thru them

i have no clue wht ur on about lol.. my php is minimal
 
Divine Celestial
Loyal Member
Joined
Nov 11, 2004
Messages
810
Reaction score
0
Apparently you won't understand it from us. Check this place out: That's a pagination tutorial.

[N]asser` ~ Out
 
Back
Top