dongpengyu1363 2014-12-26 20:48
浏览 51
已采纳

致命错误:在资源[关闭]上调用成员函数fetch_assoc()

I got this problem, which I just can't get to work.

<?php
            $sql="SELECT * FROM `news_vertical`";
            $sql2=mysql_query($sql) or die("Couldn't etablish connection with the server or username wasn't found in the database.");
            $count=mysql_num_rows($sql2);
            if($count>0)
            {
                while($row = $sql2->fetch_assoc()) {
                    if($row["Pull-LR"] == 'Right')
                    {
                        echo '<hr class="featurette-divider"><div class="row featurette"><div class="col-md-7"><h2 class="featurette-heading">', $row["title"], '</h2><span class="text-muted">- Skrevet af: ', $row["userstamp"], '</span><p class="lead">', $row["text"], '</p></div><div class="col-md-5"><img class="featurette-image img-responsive" data-src="holder.js/500x500/auto" alt="500x500" src="', $row["picture_url"], '" data-holder-rendered="true"></div></div><div class="row featurette"><div class="col-md-2 pull-left"><p>Skrevet den: ', $row["timestamp"], '</p></div></div>';
                    }
                    else if($row["Pull-LR"] == 'Left')
                    {
                        echo '<hr class="featurette-divider"><div class="row featurette"><div class="col-md-5"><img class="featurette-image img-responsive" data-src="holder.js/500x500/auto" alt="500x500" src="', $row["picture_url"], '" data-holder-rendered="true"></div><div class="col-md-7"><h2 class="featurette-heading">', $row["title"], '</h2><span class="text-muted">- Skrevet af: ', $row["userstamp"], '</span><p class="lead">', $row["text"], '</p></div></div><div class="row featurette"><div class="col-md-2 pull-right"><p>Skrevet den: ', $row["timestamp"], '</p></div></div>';
                    }
                }
            }
            else
            {
                die("Could't find 'news_vertical' database.");
            }
        ?>

I'm sure the tables are correct, it's just, I can't get it to list the information.

  • 写回答

1条回答 默认 最新

  • duanhu7400 2014-12-26 21:02
    关注

    To fix your problem, you need to use the MySQL procedural function syntax:

    while ($row = mysql_fetch_assoc($sql2)) {
        // Run your code
    }
    

    However, you shouldn't be using MySQL. Have a look at MySQLi: http://php.net/manual/en/book.mysqli.php and PDO: http://php.net/manual/en/book.pdo.php

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀