php - 错误 : mysql_fetch_array() expects parameter 1 to be resource, 中给出的 bool 值

标签 php jquery html css

我知道这个问题有超过 10 个答案,但我仍然找不到我的错误。 所以我想用五个不同的变量连接一个新闻 slider 。任何变量都是我在数据库中的帖子表中的帖子。

这是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);

      ?>

这是 slider 的代码:

  <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  ?>

最佳答案

$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";

关于php - 错误 : mysql_fetch_array() expects parameter 1 to be resource, 中给出的 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20939072/

相关文章:

javascript - 如何将 PHP 放入 Javascript 中?

javascript - 如何使用JQuery DatePicker或AngularJS单独显示星期几?

jQuery ajax 成功错误

css - div 容器 : limit to text going on one line to right

javascript - 浏览器说功能未定义(但它是)

html - 您将使用什么 HTML/CSS 来创建带背景的文本输入?

php - 我可以在 PHP 中混合使用 MySQL API 吗?

javascript - 通过电子邮件发送库存状态表

php - 带有 PHP cURL 的 GitHub API 未获得正确的状态响应

javascript - 选择元素javascript