gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 16:11:55 27 4
gpt4 key购买 nike

我知道这个问题有超过 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com