Jump to content

Pulling info from table


lmninfo

Recommended Posts

I'm trying to pull information from my database and display

the information in table format .. the table and information

looks ok however the very first line after the table headers

is screwy .. here is what I have code wise:

 

<?php //lists all users close in rank to your range
include 'connect.php';
session_start();
?>

<?php
if (isset($_SESSION['player'])) 
{
  $player=$_SESSION['player'];
  $getplayerpoints="SELECT * from km_users where playername='$player'";
  $getplayerpoints2=mysql_query($getplayerpoints) or die("Could not get player points");
  $getplayerpoints3=mysql_fetch_array($getplayerpoints2);
  $numrows="SELECT * from km_users where score>='$getplayerpoints3[score]'";
  $numrows2=mysql_query($numrows) or die("Could not grab rows");
  $numrows3=mysql_num_rows($numrows2);
  $total="SELECT * from km_users";
  $total2=mysql_query($total) or die("Could not get users");
  $total3=mysql_num_rows($total2);
  $numrows4=$numrows3+20;
  if($numrows4>=$total3)
  {
    $numrows4=$total3;
  }
  $numrows5=$numrows3-20;
  if($numrows5<0)
  {
    $numrows5=0;
  }
  print "<center>Players close to you in rank, your name is in red";
  $getrank="SELECT * from km_users order by score desc limit $numrows5,$numrows4";
  $getrank2=mysql_query($getrank) or die("Could not fetch ranks");
  print "<table border='1'>";
  print "<tr><td>Emperor</td><td>Score</td><br>";
  while($getrank3=mysql_fetch_array($getrank2))
  {
    if($getplayerpoints3[iD]==$getrank3[iD])
    {
      print "<td><font color='red'>$getrank3[playername]</font></td><td><font color='red'>$getrank3[score]</font></td></tr>";
    }
    else
    {
      print "<td>$getrank3[playername]</td><td>$getrank3[score]</td></tr>";
    }
  }
  print "</table>";
}

else
{
  print "Not Logged in";
}
?>

 

After the information is pulled from the table, the lines

emperor and score schould be at the top of the table

but instead of dropping to the next line with the first

player's empirename and score the empirename and

score are on the same line as the emperor and score

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/150146-pulling-info-from-table/
Share on other sites

<?php //lists all users close in rank to your range
include 'connect.php';
session_start();
?>

<?php
if (isset($_SESSION['player'])) 
{
  $player=$_SESSION['player'];
  $getplayerpoints="SELECT * from km_users where playername='$player'";
  $getplayerpoints2=mysql_query($getplayerpoints) or die("Could not get player points");
  $getplayerpoints3=mysql_fetch_array($getplayerpoints2);
  $numrows="SELECT * from km_users where score>='$getplayerpoints3[score]'";
  $numrows2=mysql_query($numrows) or die("Could not grab rows");
  $numrows3=mysql_num_rows($numrows2);
  $total="SELECT * from km_users";
  $total2=mysql_query($total) or die("Could not get users");
  $total3=mysql_num_rows($total2);
  $numrows4=$numrows3+20;
  if($numrows4>=$total3)
  {
    $numrows4=$total3;
  }
  $numrows5=$numrows3-20;
  if($numrows5<0)
  {
    $numrows5=0;
  }
  print "<center>Players close to you in rank, your name is in red";
  $getrank="SELECT * from km_users order by score desc limit $numrows5,$numrows4";
  $getrank2=mysql_query($getrank) or die("Could not fetch ranks");
  print "<table border='1'>";
  print "<tr><td>Emperor</td><td>Score</td><br>";
  while($getrank3=mysql_fetch_array($getrank2))
  {
    if($getplayerpoints3[iD]==$getrank3[iD])
    {
      print "<tr><td><font color='red'>$getrank3[playername]</font></td><td><font color='red'>$getrank3[score]</font></td></tr>";
    }
    else
    {
      print "<tr><td>$getrank3[playername]</td><td>$getrank3[score]</td></tr>";
    }
  }
  print "</table>";
}

else
{
  print "Not Logged in";
}
?>

You forgot to start with <tr>.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.