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 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据