错误:mysql_fetch_array()要求参数1为资源,布尔值为

时间:2014-01-05 20:57:11

标签: php jquery html css

我知道这个问题有10个以上的答案,但我仍然无法找到错误。 所以我想用五个不同的变量连接一个新闻滑块。任何变量都是db中我的posts表中的一个帖子。

这是php代码:

 <?php
       include("includes/connect.php");

    $select_posts1= "SELECT FROM posts WHERE post_id = 1";
    $select_posts2= "SELECT FROM posts WHERE post_id = 2";
     $select_posts3= "SELECT FROM posts WHERE post_id = 3";
 $select_posts4= "SELECT FROM posts WHERE post_id = 4";
 $select_posts5= "SELECT FROM posts WHERE post_id = 5";

       $run_posts1 = mysql_query($select_posts1);
    $run_posts2 = mysql_query($select_posts2);
   $run_posts3 = mysql_query($select_posts3);
 $run_posts4 = mysql_query($select_posts4);
    $run_posts5 = mysql_query($select_posts5);

      $News1=mysql_fetch_array($run_posts1);
     $News2=mysql_fetch_array($run_posts2);
     $News3=mysql_fetch_array($run_posts3);
        $News4=mysql_fetch_array($run_posts4);
    $News5=mysql_fetch_array($run_posts5);

    $post_id = $News1['post_id'];
    $post_title = $News1['post_title'];
    $post_date = $News1['post_date'];
    $post_author = $News1['post_author'];
    $post_image = $News1['post_image'];
    $post_content = substr($News1['post_content'],0,50);


    $post_id2= $News2['post_id'];
    $post_title2 = $News2['post_title'];
    $post_date2 = $News2['post_date'];
    $post_author2 = $News2['post_author'];
    $post_image2 = $News2['post_image'];
    $post_content2 = substr($News2['post_content'],0,50);


       $post_id3= $News3['post_id'];
    $post_title3 = $News3['post_title'];
    $post_date3 = $News3['post_date'];
    $post_author3 = $News3['post_author'];
    $post_image3 = $News3['post_image'];
    $post_content3 = substr($News3['post_content'],0,50);

     $post_id4= $News4['post_id'];
    $post_title4 = $News4['post_title'];
    $post_date4 = $News4['post_date'];
    $post_author4 = $News4['post_author'];
    $post_image4 = $News4['post_image'];
    $post_content4 = substr($News4['post_content'],0,50);

    $post_id5 = $News5['post_id'];
    $post_title5 = $News5['post_title'];
    $post_date5 = $News5['post_date'];
    $post_author5 = $News5['post_author'];
    $post_image5 = $News5['post_image'];
    $post_content5 = substr($News5['post_content'],0,50);

      ?>

这是滑块的代码:

  <li><center><img src="images/<?php echo $post_image; ?>" width="500" height="300"  /></center>
        <div class="panel-overlay">
          <h2><?php echo $post_title; ?></h2>
          <p align="justify"><?php echo $post_content; ?></p><br/>
          <a href="pages.php">Continue Reading &raquo;</a>
          </div>
          </li>  

          <li><center><img src="images/<?php echo $post_image2; ?>" width="500" height="300"  /></center>
        <div class="panel-overlay">
          <h2><?php echo $post_title2; ?></h2>
          <p align="justify"><?php echo $post_content2; ?></p><br/>
          <a href="pages.php">Continue Reading &raquo;</a>
          </div>
          </li> 



      <li><center><img src="images/<?php echo $post_image3; ?>" width="500" height="300"  /></center>
        <div class="panel-overlay">
          <h2><?php echo $post_title3; ?></h2>
          <p align="justify"><?php echo $post_content3; ?></p><br/>
          <a href="pages.php">Continue Reading &raquo;</a>
          </div>
          </li> 

     <li><center><img src="images/<?php echo $post_image4; ?>" width="500" height="300"  /></center>
        <div class="panel-overlay">
          <h2><?php echo $post_title4; ?></h2>
          <p align="justify"><?php echo $post_content4; ?></p><br/>
          <a href="pages.php">Continue Reading &raquo;</a>
          </div>
          </li> 



     <li><center><img src="images/<?php echo $post_image5; ?>" width="500" height="300"  /></center>
        <div class="panel-overlay">
          <h2><?php echo $post_title5; ?></h2>
          <p align="justify"><?php echo $post_content5; ?></p><br/>
          <a href="pages.php">Continue Reading &raquo;</a>
          </div>
          </li> 

    </ul>
  </div>
</div>
</div>
<?php  ?>

1 个答案:

答案 0 :(得分:3)

$select_posts1= "SELECT FROM posts WHERE post_id = 1";
$select_posts2= "SELECT FROM posts WHERE post_id = 2";
$select_posts3= "SELECT FROM posts WHERE post_id = 3";
$select_posts4= "SELECT FROM posts WHERE post_id = 4";
$select_posts5= "SELECT FROM posts WHERE post_id = 5";

在您的查询中,它缺少字段列表,而mysql返回错误。

SELECT中添加字段列表或只添加*

$select_posts1= "SELECT * FROM posts WHERE post_id = 1";
$select_posts2= "SELECT * FROM posts WHERE post_id = 2";
$select_posts3= "SELECT * FROM posts WHERE post_id = 3";
$select_posts4= "SELECT * FROM posts WHERE post_id = 4";
$select_posts5= "SELECT * FROM posts WHERE post_id = 5";