Jump to content

listing.


grlayouts

Recommended Posts

ok what i want to do it get a rank list set from a player.

 

ie the 15 people above and below them and list it.

 

what i have to list all the players is

 

<?php
print "<table border=0.5 bgcolor=AC7928>";
print "<tr><td height=20 width=35 bgcolor=#AC7928><b> <center>Rank</center></td><td width=100 bgcolor=#AC7928><b>Name</td><td width=70 bgcolor=#AC7928><b>Gang</td><td width=60 bgcolor=#AC7928><b><center>I.D</center></td><td width=30 bgcolor=#AC7928><b><center>Level</center></td><td width=100 bgcolor=#AC7928><b><center>Rank Score</center></td><td width=60 bgcolor=#AC7928><b><center>Fight</center></td></tr>";
$msel = mysql_query("select * from players where jail !='21' order by level desc limit 10000");
$ranka = 0;
while ($mem = mysql_fetch_array($msel)) {
$ranka++;
?>
<?php
$stats1=$mem[level];
$stats2=$mem[max_hp];
$stats3=$mem[wins];
$stats4=$mem[exp];
$stats4=$mem[knowledge];
$stats6=$mem[losses];
$ranks=($stats1+$stats2+$stats3+$stats4-$stats5)
?>
<?php
print "<tr><td height=15><center>$ranka</center></td><td height=15><A href=view.php?view=$mem[id]><font style=color:slategray>$mem[user]</td><td>$mem[zone1]</a> <td><center>$mem[id]</center></td><td><center>$mem[level]</center></td><td><center>$ranks</center></td></td><td ><A href=battle.php?battle=$mem[id]><font style=color:#FFFFFF><center>Attack</center></td></tr>";
}
print "</table><br>"; ?>

 

but its far too long how to i get it so every player only see's the 15 players above and below?

 

ie.

 

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

 

Admin

 

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

Link to comment
Share on other sites

I think you'd need some sort of query..

I'm not quite sure what you're using for user id's or whatever, but perhaps something like...

<?php
$slctid = mysql_query("select * from players where id=selected id"); // selects the user that is viewing the page
$startid = $slctid - 15; // sets the starting user as 15 before the viewer
$endid = $slctid + 15; // ets the last user on the list as 15 after the viewer

$msel = mysql_query("select * from players where id=$startid && jail !='21' order by level desc limit 10000");
$ranka = 0;
while ($mem = mysql_fetch_array($msel)) {
	if($startid == $endid){
	break; //if $startid reaches the $endid it stops listing users
	}
$ranka++;
?>
<?php
$stats1=$mem[level];
$stats2=$mem[max_hp];
$stats3=$mem[wins];
$stats4=$mem[exp];
$stats4=$mem[knowledge];
$stats6=$mem[losses];
$ranks=($stats1+$stats2+$stats3+$stats4-$stats5)

$startid++ //increments to the user id
?>

 

I have no idea if this would work as I haven't tested it, but it's a start

Link to comment
Share on other sites

haha! oops.. forgot to echo it :P

 

just before

$startid++; //increments to the user id

put

echo $stats1 . " " . $stats2 . " " . $stats3 . " " . $stats4 . " " . $stats5 . " " . $stats6 . " " . $ranks . "<br />";

 

and see what happens.

 

 

EDIT: realised I'd missed off the "; at the end of the echo...

Link to comment
Share on other sites

um.. I've just made a couple of changes.. the code I've got is

<?php
$slctid = mysql_query("select * from players where id=selected id"); // selects the user that is viewing the page MUST BE DIFFERENT FROM $mem
$startid = $slctid - 15; // sets the starting user as 15 before the viewer
$endid = $slctid + 15; // ets the last user on the list as 15 after the viewer

$msel = mysql_query("select * from players where id=$startid && jail !='21' order by level desc limit 10000");
$ranka = 0;
while ($mem = mysql_fetch_array($msel)) {
	if($startid = $endid){
	break; //if $startid reaches the $endid it stops listing users
	}
$ranka++;

$stats1=$mem[level];
$stats2=$mem[max_hp];
$stats3=$mem[wins];
$stats4=$mem[exp];
$stats4=$mem[knowledge];
$stats6=$mem[losses];
$ranks=($stats1+$stats2+$stats3+$stats4-$stats5)

echo $stats1 . " " . $stats2 . " " . $stats3 . " " . $stats4 . " " . $stats5 . " " . $stats6 . " " . $ranks . "<br />";

$startid++ //increments to the user id
}
?>

You need to make sure that the $slctid is different to the $startid and $endid. $slctid would be the original id of the member viewing the page.

Link to comment
Share on other sites

hi, sorry if this is of the topic:

 

could you not use limits in your SQL query. I see you get the the following, $slctid, $startid, $endid.

 

could you not use those in your query to get only the 15 before and 15 after $slctid (current user)

 

i.e.

$msel = mysql_query("select * from players where id=$startid && jail !='21' order by level desc limit $startid,30");

//this should then get the next 30 records starting at 15 below the currents users

 

should this not then get only the records your looking for?

sorry again if this is not want you wanted

 

 

also just noticed: is the problem that your only getting one record not maybe because of you MySQL query, can more than one user have the same rank?

 

select * from players where id=$startid // will that not ONLY get the player with the specific rank?

Link to comment
Share on other sites

now the code i have is.

 

<?php
$slctid = mysql_query("select * from players where id=$stat[id]"); // selects the user that is viewing the page MUST BE DIFFERENT FROM $mem
$startid = $slctid - 15; // sets the starting user as 15 before the viewer
$endid = $slctid + 15; // ets the last user on the list as 15 after the viewer

$msel = mysql_query("select * from players where id=$stat[id] && jail !='21' order by level desc limit $stat[id],30");
$ranka = 0;
while ($mem = mysql_fetch_array($msel)) {
	if($startid = $endid){
	break; //if $startid reaches the $endid it stops listing users
	}
$ranka++;

$stats1=$mem[level];
$stats2=$mem[max_hp];
$stats3=$mem[wins];
$stats4=$mem[exp];
$stats4=$mem[knowledge];
$stats6=$mem[losses];
$ranks=($stats1+$stats2+$stats3+$stats4-$stats5);

echo $stats1 . " " . $stats2 . " " . $stats3 . " " . $stats4 . " " . $stats5 . " " . $stats6 . " " . $ranks . "<br />";

$startid++ //increments to the user id

?>

but its now displaying nothing.

Link to comment
Share on other sites

select * from players where id=$startid // will that not ONLY get the player with the specific rank?

I was meaning for that to select only the user with an id equal to $startid. As start id is incresed by 1 each time it would works it's way down the list until reaching $endid.

 

$msel = mysql_query("select * from players where id=$startid && jail !='21' order by level desc limit $startid,30");

sounds good.. I didn't know about that ::)

although it would be 15, not 30, as he's wanting to show only 15 below. The other 15 are the 15 above in the database.

Link to comment
Share on other sites

hi, you have not closed your while loop

 

while ($mem = mysql_fetch_array($msel)) {

if($startid = $endid){

break; //if $startid reaches the $endid it stops listing users

}

$ranka++;

 

$stats1=$mem[level];

$stats2=$mem[max_hp];

$stats3=$mem[wins];

$stats4=$mem[exp];

$stats4=$mem[knowledge];

$stats6=$mem[losses];

$ranks=($stats1+$stats2+$stats3+$stats4-$stats5);

 

echo $stats1 . " " . $stats2 . " " . $stats3 . " " . $stats4 . " " . $stats5 . " " . $stats6 . " " . $ranks . "<br />";

 

$startid++ //increments to the user id

 

}

 

 

 

by the way, how do you display code as code? sorry im new here

Link to comment
Share on other sites

hi, you have not closed your while loop

I just mentioned that, but I think that's what just caused the

Parse error: syntax error, unexpected '}' in /home/hobotown/public_html/ranks2.php on line 76

message..

Not sure why though.

Link to comment
Share on other sites

just notice your $stats variables.. probably not what's causing the problem, but you should have '' around them...

$stats1=$mem['level'];
$stats2=$mem['max_hp'];
$stats3=$mem['wins'];
$stats4=$mem['exp'];
$stats4=$mem['knowledge'];
$stats6=$mem['losses'];

Just a note as exp is a statement by itself and may confuse the script. the '' just stops it getting confused.

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.