PHP question

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
Ravinos
Posts: 281
Joined: Tue Sep 15, 2009 4:14 pm

PHP question

Post by Ravinos »

I've looked a few different places so far and haven't been able to find the answer.

How would I create a table that displays all the users in the game but limit to only 10 at a time with a "page next" option to scroll through the pages? I guess this could also be used on large lists of equipment too for the shops.

Right now I have the weapons and armor shops loading in Spry collapsible panels to help get rid of the clutter. Same with the member list.
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: PHP question

Post by hallsofvallhalla »

here is what i wrote for planetary wars

Code: Select all

<?php
  if(!isset($start))
  {
    $start=0;
  }
  $order="SELECT * from gamers";
  $order2=mysql_query($order);
  $d=0;
  $f=0;
  $g=1;
  print "<center>Page: ";
  while($order3=mysql_fetch_array($order2))
  {
    if($f%20==0)
    {
      print "<A href='top.php?start=$d'>$g</a> ";
      $g++;
    }
    $d=$d+1;
    $f++;
  }
  print "</center><center>Players by Level<br>";
  print "<table border='2' bordercolor='white' bgcolor='#000000'><tr><td>ID#</td><td>Player</td><td>Level</td><td>Profession</td></tr>";
  $topplayers="SELECT * from gamers order by level DESC Limit $start, 20";
  $topplayers2=mysql_query($topplayers) or die("Could not query players");
  while($topplayer3=mysql_fetch_array($topplayers2))
  {
    $topplayer3[playername]=strip_tags($topplayer3[playername]);
    print "<tr><td>$topplayer3[id]</td><td>$topplayer3[playername]</td><td>$topplayer3[level]</td><td>$topplayer3[profession]</td></tr>";
  }
  print "</table>";
  echo "<br />";
   print "<A href='index.php'>Go to Main Page</a>";
?>
User avatar
Ravinos
Posts: 281
Joined: Tue Sep 15, 2009 4:14 pm

Re: PHP question

Post by Ravinos »

Awesome. I'll give it a go and see what happens tomorrow.
Loopy

Re: PHP question

Post by Loopy »

Sounds like you're pretty early in your development, but some other things to consider in the future would be modifying your SQL statement to omit listing players that are banned/inactive from your page results.

For my own game, which I'm still developing, the best way for a player to improve his rank is to fight players within 10 ranks of himself or higher. The reputation/reward system discourages high level players from attacking low level players for farming, so when I display my search results, I display the ten players ranked immediately above the player, and the 10 players ranked immediately below.

So my results look something like this (abbreviated to 2 higher and 2 lower):

higherPlayer2
higherPlayer1
You
lowerPlayer1
lowerPlayer2
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: PHP question

Post by hallsofvallhalla »

thats a good idea. Adding a field called active, then in the query add where active = 1
User avatar
Ravinos
Posts: 281
Joined: Tue Sep 15, 2009 4:14 pm

Re: PHP question

Post by Ravinos »

This is something I overlooked when I started designing the games layout. I've been mainly focusing on the combat system, skill experience, and quests. I have 20 test characters and it fills up pages pretty quick lol.

With my current player list users can sort by level, highest skill, last online, alive or dead status, pvp flag, money earned, and most kills. I just couldn't get it to limit it to number x then do page next or page previous. The x limit isn't the hard part lol.

I haven't tried to use this code yet but I should be able to give it a try this afternoon or tomorrow.
Post Reply

Return to “Advanced Help and Support”