简体   繁体   English

php-echo 未从数据库中显示

[英]php- echo not displaying from database

I have a database in 'test' called 'leaderboard'... fields are 'id, name,g-b_ratio'我在“测试”中有一个名为“排行榜”的数据库......字段是“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?为什么会这样?

Do you realize there is a semicolon after your while() statement?您是否意识到您的 while() 语句后面有一个分号?

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?删除该分号并重试?

  • $row['name'] is empty $row['name'] 为空
  • 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";
}

Use mysql_fetch_assoc($result) .使用mysql_fetch_assoc($result)

In this way you can call $row['name'] .通过这种方式,您可以调用$row['name']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM