数据库值检索错误显示

时间:2015-12-24 06:01:04

标签: php mysql database

警告:mysql_fetch_array()期望参数1是资源... 当我试图从数据库获取下面的第一个特色配置文件的值时,会显示以上错误..... 如果我添加: -         或死(mysql_error()); 然后它显示没有选择数据库.. 请帮忙   代码: -

<div class="grid_1">
      <div class="container">
        <h1>Featured Profiles</h1>
        <div class="heart-divider">
            <span class="grey-line"></span>
            <i class="fa fa-heart pink-heart"></i>
            <i class="fa fa-heart grey-heart"></i>
            <span class="grey-line"></span>
        </div>
<?php
    $sql="SELECT (file,user_name,user_id,user_occupation) FROM users1";
    $result_set=mysql_query($sql) or die(mysql_error());
        while($row=mysql_fetch_object($result_set))
    {
        ?>

        <ul id="flexiselDemo3">
          <li><div class="col_1"><a href="view_profile.html">
            <img src="images/<?php echo $row->file ?>" alt="" class="hover-animation image-zoom-in img-responsive"/>
             <div class="layer m_1 hidden-link hover-animation delay1 fade-in">
                <div class="center-middle">About Him</div>
             </div>
             <h3><span class="m_3">Profile ID : <?php echo $row->user_id ?></span><br>28, Christian, Australia<br>Corporate</h3></a></div>
          </li>
          <li><div class="col_1"><a href="view_profile.html">
            <img src="images/2.jpg" alt="" class="hover-animation image-zoom-in img-responsive"/>
             <div class="layer m_1 hidden-link hover-animation delay1 fade-in">
                <div class="center-middle">About Her</div>
             </div>
             <h3><span class="m_3">Profile ID : MI-387412</span><br>28, Christian, Australia<br>Corporate</h3></a></div>
          </li>
          <li><div class="col_1"><a href="view_profile.html">
            <img src="images/3.jpg" alt="" class="hover-animation image-zoom-in img-responsive"/>
             <div class="layer m_1 hidden-link hover-animation delay1 fade-in">
                <div class="center-middle">About Him</div>
             </div>
             <h3><span class="m_3">Profile ID : MI-387412</span><br>28, Christian, Australia<br>Corporate</h3></a></div>
          </li>
          <li><div class="col_1"><a href="view_profile.html">
            <img src="images/4.jpg" alt="" class="hover-animation image-zoom-in img-responsive"/>
             <div class="layer m_1 hidden-link hover-animation delay1 fade-in">
                <div class="center-middle">About Her</div>
             </div>
             <h3><span class="m_3">Profile ID : MI-387412</span><br>28, Christian, Australia<br>Corporate</h3></a></div>
          </li>
          <li><div class="col_1"><a href="view_profile.html">
            <img src="images/5.jpg" alt="" class="hover-animation image-zoom-in img-responsive"/>
             <div class="layer m_1 hidden-link hover-animation delay1 fade-in">
                <div class="center-middle">About Him</div>
             </div>
             <h3><span class="m_3">Profile ID : MI-387412</span><br>28, Christian, Australia<br>Corporate</h3></a></div>
          </li>
          <li><div class="col_1"><a href="view_profile.html">
            <img src="images/6.jpg" alt="" class="hover-animation image-zoom-in img-responsive"/>
             <div class="layer m_1 hidden-link hover-animation delay1 fade-in">
                <div class="center-middle">About Her</div>
             </div>
             <h3><span class="m_3">Profile ID : MI-387412</span><br>28, Christian, Australia<br>Corporate</h3></a></div>
          </li>
        </ul>
        <script type="text/javascript">
         $(window).load(function() {
            $("#flexiselDemo3").flexisel({
                visibleItems: 6,
                animationSpeed: 1000,
                autoPlay:false,
                autoPlaySpeed: 3000,            
                pauseOnHover: true,
                enableResponsiveBreakpoints: true,
                responsiveBreakpoints: { 
                    portrait: { 
                        changePoint:480,
                        visibleItems: 1
                    }, 
                    landscape: { 
                        changePoint:640,
                        visibleItems: 2
                    },
                    tablet: { 
                        changePoint:768,
                        visibleItems: 3
                    }
                }
            });

        });
       </script>
       <script type="text/javascript" src="js/jquery.flexisel.js"></script>

        <?php
            }
        ?>

    </div>
</div>

2 个答案:

答案 0 :(得分:1)

我认为问题出在你的$ result函数中它应该有2个参数而你只给了一个所以你的代码应该是这样的

<?php
$connection=mysqli_connect('localhost','yourmysqlusername','yourmysqlpassword','yourmysqldatabase');
     $sql="SELECT (file,user_name,user_id,user_occupation) FROM users1";
    //you have to add $connection as 2nd parameter in $result function
        $result_set=mysql_query($connection,$sql) or die(mysql_error());
            while($row=mysql_fetch_object($result_set))
?>

答案 1 :(得分:0)

确保首先使用mysql_select连接到数据库,然后使用mysql_select_db选择数据库。在此之后,您需要使用mysql_query启动查询。

此外,您可以mysqli_connect组合前两个步骤。见this