Table not displaying properly?

Discussion in 'PHP' started by mokimofiki, May 20, 2009.

  1. #1
    The information from the mySQL database is not showing up? The playerstats table is there ande there is a record called level in the table ... any other thoughts?

    echo "<table width=\"800\" border=\"0\">";
    echo "<tr>";
    echo "<td width=\"200\"><u>Player Name</u></td>";
    echo "<td width=\"100\"><u>Player level</u></td>";
    echo "<td width=\"225\"><u>Cash On Hand</u></td>";
    echo "<td width=\"150\"><u>Gang Size</u></td>";
    echo "<td width=\"125\"><center><u>Action</u></center></td>";
    echo "</tr>"; 
     
    $resultfight = mysql_query("SELECT * FROM playerstats WHERE level = 5 ORDER BY rand() LIMIT 15") or die(mysql_error());
    $rowfight = mysql_fetch_array($resultfight);
    
    while($rowfight = mysql_fetch_array($resultfight))
      {
      echo "<tr>";
      echo "<td>" . $rowfight['name'] . "</td>";
      echo "<td><b>" . $rowfight['level'] . "</b></td>";
      echo "<td>\$" . $rowfight['gold'] . "</td>";
      echo "<td>" . $rowfight['gang'] . "</td>";
      echo "<td>Action button</td>";
      echo "</tr>";
      }
    
    echo "</table>";
    Code (markup):

     
    mokimofiki, May 20, 2009 IP
  2. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #2
    $resultfight = mysql_query("SELECT * FROM playerstats WHERE level = 5 ORDER BY rand() LIMIT 15") or die(mysql_error());
    $rowfight = mysql_fetch_array($resultfight);

    while($rowfight = mysql_fetch_array($resultfight))
    {
    echo "<tr>";
    echo "<td>" . $rowfight['name'] . "</td>";
    echo "<td><b>" . $rowfight['level'] . "</b></td>";
    echo "<td>\$" . $rowfight['gold'] . "</td>";
    echo "<td>" . $rowfight['gang'] . "</td>";
    echo "<td>Action button</td>";
    echo "</tr>";
    }


    The issue seems to be in this bit of code here ... anybody?
     
    mokimofiki, May 20, 2009 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    Instead of running the mysql_query as you do now, do as follows:
    $resultfight = ("SELECT * FROM playerstats WHERE level = 5 ORDER BY rand() LIMIT 15") or die(mysql_error());
    echo $resultfight; //this shows you how the query looks, and then you just copy that and run it through phpmyadmin to see what happens
     
    PoPSiCLe, May 20, 2009 IP
  4. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #4
    the result is .... resource id #8?
     
    mokimofiki, May 20, 2009 IP
  5. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Add single quotes around 5 (WHERE level = '5').
     
    SHOwnsYou, May 20, 2009 IP
  6. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #6
    $playerlevel = "5";

    $resultfight = mysql_query("SELECT * FROM playerstats WHERE level = '$playerlevel' ORDER BY rand() LIMIT 15") or die(mysql_error());
    $rowfight = mysql_fetch_array($resultfight);

    while($rowfight = mysql_fetch_array($resultfight))
    {
    echo "<tr>";
    echo "<td>" . $rowfight['name'] . "</td>";
    echo "<td><b>" . $rowfight['level'] . "</b></td>";
    echo "<td>\$" . $rowfight['gold'] . "</td>";
    echo "<td>" . $rowfight['gang'] . "</td>";
    echo "<td>Action button</td>";
    echo "</tr>";
    }
    echo "</table>";

    ok this is what I have now and it still gives me a resource id #8 as the result for:
    echo $resultfight;
     
    mokimofiki, May 20, 2009 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    Did you try doing what I told you to do? Remove the "mysql_query" part, echo the SELECT-statement, and run it through the SQL-query in phpmyadmin?
     
    PoPSiCLe, May 20, 2009 IP
  8. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #8
    Yes and it kicks out the proper records just the way I want it to....

    I just can't seem to see why it wont from the page
     
    mokimofiki, May 20, 2009 IP
  9. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #9
    Found the problem (stupid me)

    $resultfight = mysql_query("SELECT * FROM playerstats WHERE level = '$playerlevel' ORDER BY rand() LIMIT 15") or die(mysql_error());
    [COLOR="Red"]$rowfight = mysql_fetch_array($resultfight); //remove this line[/COLOR]
    
    while($rowfight = mysql_fetch_array($resultfight))
    {
    echo "<tr>";
    echo "<td>" . $rowfight['name'] . "</td>";
    echo "<td><b>" . $rowfight['level'] . "</b></td>";
    echo "<td>\$" . $rowfight['gold'] . "</td>";
    echo "<td>" . $rowfight['gang'] . "</td>";
    echo "<td>Action button</td>";
    echo "</tr>";
    }
    echo "</table>";
    Code (markup):
     
    mokimofiki, May 20, 2009 IP
  10. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #10
    // WRONG
    WHERE level = 5

    //RIGHT
    WHERE level = "5"
     
    ezprint2008, May 21, 2009 IP
  11. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #11
    Seriously - if you don't know what you are talking about, why talk at all?

    I beg of you to try that in the query from the OP. See what happens, so to speak.

    Now, if you'd said:
    WHERE level = '5'

    It would have made so much more sense...
     
    PoPSiCLe, May 21, 2009 IP