grlayouts Posted April 17, 2007 Share Posted April 17, 2007 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 Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 17, 2007 Author Share Posted April 17, 2007 ne1? Quote Link to comment Share on other sites More sharing options...
AndyB Posted April 17, 2007 Share Posted April 17, 2007 In the context of a query like "select * from players where jail !='21' order by level .." what does 'above' and 'below' mean? Above and below what? Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 17, 2007 Author Share Posted April 17, 2007 I mean it ranks by level. I just want it to just show the people 15 above or below that player. to cut the list for each player. or they can only attack 2 levels higher and lower so show all those people. Quote Link to comment Share on other sites More sharing options...
Dragen Posted April 17, 2007 Share Posted April 17, 2007 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 Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 17, 2007 Author Share Posted April 17, 2007 Parse error: syntax error, unexpected T_VARIABLE in /home/hobotown/public_html/ranks2.php on line 62 line 62: $startid++ Quote Link to comment Share on other sites More sharing options...
Dragen Posted April 17, 2007 Share Posted April 17, 2007 try this $ranks=($stats1+$stats2+$stats3+$stats4-$stats5); $startid++; //increments to the user id ?> Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 17, 2007 Author Share Posted April 17, 2007 yeah goes through but displays nothing. Quote Link to comment Share on other sites More sharing options...
Dragen Posted April 17, 2007 Share Posted April 17, 2007 haha! oops.. forgot to echo it 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... Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 17, 2007 Author Share Posted April 17, 2007 1 100 2 0.000 1 103 im getting this? which is only my stats. no one elses. Quote Link to comment Share on other sites More sharing options...
Dragen Posted April 17, 2007 Share Posted April 17, 2007 is it just showing the once? or repeating.. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 17, 2007 Author Share Posted April 17, 2007 just the once, only my stat then nothing? Quote Link to comment Share on other sites More sharing options...
Dragen Posted April 17, 2007 Share Posted April 17, 2007 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. Quote Link to comment Share on other sites More sharing options...
saint959 Posted April 17, 2007 Share Posted April 17, 2007 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? Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 17, 2007 Author Share Posted April 17, 2007 yes more than on player can ie. 1 stedders 97 6 558.49 Attack 2 paws 343 6 497.46 Attack 3 The Goon 2 3 732.68 Attack Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 17, 2007 Author Share Posted April 17, 2007 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. Quote Link to comment Share on other sites More sharing options...
Dragen Posted April 17, 2007 Share Posted April 17, 2007 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. Quote Link to comment Share on other sites More sharing options...
Dragen Posted April 17, 2007 Share Posted April 17, 2007 change the last part.. $startid++; //increments to the user id } ?> Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 17, 2007 Author Share Posted April 17, 2007 Parse error: syntax error, unexpected '}' in /home/hobotown/public_html/ranks2.php on line 76 ok so what should the code be? Quote Link to comment Share on other sites More sharing options...
saint959 Posted April 17, 2007 Share Posted April 17, 2007 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 Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 17, 2007 Author Share Posted April 17, 2007 [ code ] Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 17, 2007 Author Share Posted April 17, 2007 ok its displaying nothing. Quote Link to comment Share on other sites More sharing options...
Dragen Posted April 17, 2007 Share Posted April 17, 2007 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. Quote Link to comment Share on other sites More sharing options...
Dragen Posted April 17, 2007 Share Posted April 17, 2007 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. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 17, 2007 Author Share Posted April 17, 2007 ok now im confused... so i have the script in place and its displaying nothing. not even my record now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.