• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook pagefor updates, or we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.)

Rangking list php

Newbie Spellweaver
Joined
Jun 21, 2013
Messages
30
Reaction score
1
rangkinglist.php
PHP:
<!--rangking list-->
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("db_game") or die (mysql_error());

// jumlah data yang akan ditampilkan
$dataPerPage = 50;

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

$offset = ($noPage - 1) * $dataPerPage;
 
// membaca nomor halaman
$noPage = $_GET['page'];
 
// membuat nomor urut awal di setiap halaman berdasarkan formula di atas
$i = $noPage + ($noPage - 1) * ($dataPerPage - 1);

$result = mysql_query("SELECT * FROM t_user WHERE pv < 9 ORDER BY totalexp DESC LIMIT $offset, $dataPerPage")
or die(mysql_error());  


echo "<table border='1'>";
echo "<tr>
    <th>No.</th>
    <th>Name</th>
    <th>Level</th>
    <th>Exp</th>
    <th>Guild</th>
      </tr>";

while($row = mysql_fetch_array($result))
{
    echo "<tr><td>"; 
    echo $i;
    echo "</td><td>"; 
    echo $row['name'];
    echo "</td><td>"; 
    echo $row['level'];
    echo "</td><td>"; 
    echo $row['totalexp'];
    echo "</td><td>"; 
    echo $row['guild'];
    echo "</td></tr>"; 
$i++;
} 
echo "</table>";

// tambahan
$query = "SELECT COUNT(*) AS jumData FROM t_user WHERE pv < 6 ORDER BY totalexp DESC";
$hasil = mysql_query($query);
$data = mysql_fetch_array($hasil);

$jumData = $data['jumData'];

$jumPage = ceil($jumData/$dataPerPage);

if ($noPage > 1) echo  "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage-1)."'><< Prev</a>";

for($page = 1; $page <= $jumPage; $page++)
{
         if ((($page >= $noPage - 3) && ($page <= $noPage + 3)) || ($page == 1) || ($page == $jumPage))
         {
            if (($showPage == 1) && ($page != 2))  echo "...";
            if (($showPage != ($jumPage - 1)) && ($page == $jumPage))  echo "...";
            if ($page == $noPage) echo " <b>".$page."</b> ";
            else echo " <a href='".$_SERVER['PHP_SELF']."?page=".$page."'>".$page."</a> ";
            $showPage = $page;
         }
}

if ($noPage < $jumPage) echo "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage+1)."'>Next >></a>";
?>
Juminten - Rangking list php - RaGEZONE Forums
thank's
WhatThePho

-> original sript http://forum.ragezone.com/f705/release-ranking-page-total-accounts-777354-post6521096/#post6521096
 
Junior Spellweaver
Joined
Dec 31, 2010
Messages
144
Reaction score
16
rangkinglist.php
PHP:
<!--rangking list-->
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("db_game") or die (mysql_error());

// jumlah data yang akan ditampilkan
$dataPerPage = 50;

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

$offset = ($noPage - 1) * $dataPerPage;
 
// membaca nomor halaman
$noPage = $_GET['page'];
 
// membuat nomor urut awal di setiap halaman berdasarkan formula di atas
$i = $noPage + ($noPage - 1) * ($dataPerPage - 1);

$result = mysql_query("SELECT * FROM t_user WHERE pv < 9 ORDER BY totalexp DESC LIMIT $offset, $dataPerPage")
or die(mysql_error());  


echo "<table border='1'>";
echo "<tr>
    <th>No.</th>
    <th>Name</th>
    <th>Level</th>
    <th>Exp</th>
    <th>Guild</th>
      </tr>";

while($row = mysql_fetch_array($result))
{
    echo "<tr><td>"; 
    echo $i;
    echo "</td><td>"; 
    echo $row['name'];
    echo "</td><td>"; 
    echo $row['level'];
    echo "</td><td>"; 
    echo $row['totalexp'];
    echo "</td><td>"; 
    echo $row['guild'];
    echo "</td></tr>"; 
$i++;
} 
echo "</table>";

// tambahan
$query = "SELECT COUNT(*) AS jumData FROM t_user WHERE pv < 6 ORDER BY totalexp DESC";
$hasil = mysql_query($query);
$data = mysql_fetch_array($hasil);

$jumData = $data['jumData'];

$jumPage = ceil($jumData/$dataPerPage);

if ($noPage > 1) echo  "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage-1)."'><< Prev</a>";

for($page = 1; $page <= $jumPage; $page++)
{
         if ((($page >= $noPage - 3) && ($page <= $noPage + 3)) || ($page == 1) || ($page == $jumPage))
         {
            if (($showPage == 1) && ($page != 2))  echo "...";
            if (($showPage != ($jumPage - 1)) && ($page == $jumPage))  echo "...";
            if ($page == $noPage) echo " <b>".$page."</b> ";
            else echo " <a href='".$_SERVER['PHP_SELF']."?page=".$page."'>".$page."</a> ";
            $showPage = $page;
         }
}

if ($noPage < $jumPage) echo "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage+1)."'>Next >></a>";
?>

thank's
WhatThePho

-> original sript http://forum.ragezone.com/f705/release-ranking-page-total-accounts-777354-post6521096/#post6521096


PHP_SELF a very vulnerable spot there , mysql api long since dead , right now trending is PDO

PHP:
<?php
class toserver
{
private $db , $query ;
function __construct($host,$mysql_root,$mysql_pass)
{
        $dsn = sprintf('mysql:host=%s;dbname=%s', $host, Null);
        $pdo = new PDO($dsn, $mysql_root, $mysql_pass);
        $pdo->setAttribute(PDO::ATTR_TIMEOUT, 1);
        $pdo->setAttribute(PDO::ATTR_PERSISTENT, false);
        $pdo->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, 'SET NAMES utf8');
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
        $this->db = $pdo;
}
public function get_ranking($limit = null)
{
$ranking = "<table border='1'><tr><th>Rank</th><th>Name</th><th>Level</th><th>Guild</th></tr>";
$i = 1;
      $this->query =  $this->db->prepare( sprintf('SELECT * FROM `db_game`.`t_user` WHERE `t_user`.`pv` <=4 AND `t_user`.`deleted` = 0 ORDER BY `t_user`.`totalexp` DESC %s', ($limit ? 'limit '.$limit : null)));
   $this->query->execute();
if($this->query->rowCount()>=1)
{
foreach($this->query->fetchAll(PDO::FETCH_OBJ) as $data)
{
 $ranking .= sprintf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",$i,$data->name,$data->level,($data->guild ? $data->guild : 'No Guild'));
$i++;
}
$ranking .= "</table>";
echo $ranking;
}
}
}
$ranking = new toserver('localhost','root','password');
$ranking->get_ranking(10);// 10 -> limit change to ur requirement
?>



Advantage is code is lot shorter neater and better implemented , in OOP method i have my own commercial CMS for TO which is being used by top servers right now
 
Last edited:
Back
Top