Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php- echo not displaying from database

Tags:

html

php

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?

like image 641
Louismoore18 Avatar asked Apr 01 '26 23:04

Louismoore18


1 Answers

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?

like image 57
aparker Avatar answered Apr 04 '26 12:04

aparker