Jump to content
Sign in to follow this  
cyberfly

Membuat Ranking (php Mysql)

Recommended Posts

rankingmn1.jpg

Seperti gmbar di atas, column tempat tu merupakan kedudukan peserta yg disort berdasarkan jumlah markah tertinggi.

Masalah ialah,bila aku klik link ke page 2,tempat tu akan papar no 1 balik.bukan no 17.data yg lain semua dah betul.cuma no tu je.

no coding aku untuk no tu :

 <?php
$single="SELECT * FROM (SELECT *,game1+game2+game3+game4+game5+game6 AS 'JumlahMarkah' FROM markah WHERE idFormat='4' AND idPertandingan='$idpertandingan') temp ORDER BY JumlahMarkah DESC";
$pager = new pager($single,'page',25);
$kedudukan = 0;
while($array = mysql_fetch_array($pager->result)){                  
 ?>
<?php $kedudukan = $kedudukan + 1; ?>

Share this post


Link to post
Share on other sites

var $kedudukan tu ko kena ubah skit

cth aku buat

<?php

mysql_connect('localhost','root','');

mysql_select_db('try');

//limit view data per page

$limit = 2;

// jika nilai di atas kosong, maka tetapkan nilai default untuk $offset

if(empty($_GET['page']))

{

$offset = 0;

$page=1;}

else

{

$offset = ($_GET['page']-1) * $limit;

}

?>

<table border=1">

<tr>

<td>No</td>

<td>ID</td>

<td>Data</td>

</tr>

<?php

$kaunter=0;

$qid = mysql_query("select * from next_previous limit $offset,$limit");

while($data = mysql_fetch_array($qid))

{

$kaunter++;

$no = $offset + $kaunter;

echo "<tr>";

echo "<td>$no</td>";

echo "<td>$data['id]</td>";

echo "<td>$data['data']</td>";

echo "</td></tr>";

}

?>

</table>

<?php

// untuk menghasilkan << 1 2 3 >>

$qid = mysql_query('select id from next_previous');

$total = mysql_num_rows($qid);

//untuk mengetahui jumlah halaman

$total_page = ceil($total/$limit);

// echo link ke halaman sebelum

if(!empty($_GET['page']) && $_GET['page'] != 1)

{

$previous_page = $page-1;

echo '<a href=test.php?page=' . $previous_page . '"><<</a>';

}

else

{ echo "<<"; }

// untuk 1 2 3 4 5

for($i=1;$i<=$total_page;$i++)

{

echo ' <a href="test.php?page=' . $i . '">' . $i . '</a> ';

}

// untuk link kehalaman berikut

if($_GET['page] < $total_page)

{

$next_page = $page+1;

echo '<a href="test.php?page=' . $next_page . '">>></a>';

}

else

{ echo ">>"; }

?>

http://www.ejoe.net/forum/tutorial_view.ph...e=php&id=86

Edited by ejoe

Share this post


Link to post
Share on other sites

$qid = mysql_query("select * from next_previous limit $offset,$limit");

while($data = mysql_fetch_array($qid))

{

$kaunter++;

$no = $offset + $kaunter;

sql aku tu ader guna var $offset, then masa nak kira bil tu aku akan guna $offset tu nak kira

better ko amik cth aku bg n masukkan sql ko

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...