donglu1472 2013-07-14 20:21
浏览 88
已采纳

MySQL表条目没有显示出来

I began building a CMS for a blog today, and have had trouble getting the two entries I manually inserted via phpMyAdmin to show up on the page. It might be an issue with the database, might be an issue with the code, but for some reason the MySQL table iterates through only once with blank entries. Here is the PHP:

$link = mysql_connect('localhost', 'root','');
    if (!$link)
        die('<h3>Cound not connect to MySQL<h3><p><div>'.mysql_error()."</p></div>");
    mysql_select_db('blog_cms', $link);
    $posts = mysql_query("SELECT * FROM entries");
    if ($posts == null) die ("<h3>No blog posts found!</h3><div><p>Something went wrong.</p></div>");
    else
        while ($entry = mysql_fetch_row($posts)); {
            echo "<h3>".$entry[0]."</h3>";
            echo "<div>";
            echo "<p>".$entry[1]."</p>";
            echo "</div>";
        }

And for the output HTML I am simply getting

<h3></h3><div><p></p></div>

Screenshot of phpMyAdmin PMA screenshot

Why is this only returning a single blank row?

  • 写回答

1条回答 默认 最新

  • dozpv84422 2013-07-14 20:24
    关注

    There's an extra ; after your while loop That's why the next block is not associated with this loop any more.

     while ($entry = mysql_fetch_row($posts));
                                             A
    

    remove the extra ; and it should work fine :) And please note that mysql_* functions are deprecated. Start using PDO or mysqli_*.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度