Louismoore18
Louismoore18

Reputation: 167

php- echo not displaying from database

I have a database in 'test' called 'leaderboard'... fields are 'id, name,g-b_ratio'

my code....

    <div class="leaderboard">
<?php
mysql_select_db("test")  or die("Cannot select the database");
$result = mysql_query("SELECT * FROM leaderboard") or die("Cannot select the database");
while($row = mysql_fetch_array($result)); 
{
echo $row['name']; } ?>

      </div>    

is not displaying anything from database.

why is it happening?

Upvotes: 3

Views: 193

Answers (3)

iskandarm
iskandarm

Reputation: 109

Use mysql_fetch_assoc($result).

In this way you can call $row['name'].

Upvotes: -1

aparker
aparker

Reputation: 178

Do you realize there is a semicolon after your while() statement?

while($row = mysql_fetch_array($result)); 
{
echo $row['name']; }

I imagine it iterates to the last row before the echo is ever reached. Remove that semicolon and try again?

Upvotes: 4

genesis
genesis

Reputation: 50982

  • $row['name'] is empty
  • there are no rows in leaderboard table
  • you can try something like

--

if (!mysql_num_rows($result)){
   echo "There are no rows in leaderboard table";
}

Upvotes: 2

Related Questions