这似乎是重复的问题,但我尝试了所有已经发布的答案。
这是我的代码
include"db.php";
//$poster_id=1;
$sql = "SELECT pi.full_name,pi.poster_img,pi.poster_tag,
p.post_title,p.post_description,p.post_tag,
p.post_snap
FROM POSTS p JOIN POSTER_INFO pi ON p.poster_id=pi.auth_id";
$result = mysql_query($sql) or die(mysql_error());
echo mysql_error();
$msg=" ";
while($row = mysql_fetch_array($result)) {
$msg_footer="<div class='post_footer'>";
$msg_footer=$msg_footer."<div class='post_img'>";
$msg_footer=$msg_footer."<img src='". 'data:image/jpeg;base64,' . base64_encode( $row[6] ) ."' width='330' height='130' /></div>";
$msg_footer=$msg_footer."<div class='post_author'><div class='author_img'><img src='". 'data:image/jpeg;base64,' . base64_encode( $row[1] ) ."' width='80' height='80' /></div>";
$msg_footer=$msg_footer."<div class='author_info'><b>". $row[0] ."</b><br/><span style='font-size:11px'>". $row[2] ."</span><br/><span style='font-size:10px'>1 Post</span></div></div></div>";
$msg .= " <li><br/><span class='post_title'>". $row[3] ."</span><br/><br/><span class='post_description'>" . $row[4] . "</span></li>";
$msg .=$msg_footer; //WARNING POINTING TO THIS LINE
}
我收到警告,它指向 while 循环的最后一行;
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\labs\load_data.php on line 40
我的 sql 查询是正确的,因为我试图在 sql 编辑器和 php 页面中执行它。像这样
<?php
$sql = "SELECT pi.full_name,pi.poster_img,pi.poster_tag,
p.post_title,p.post_description,p.post_tag,
p.post_snap
FROM POSTS p JOIN POSTER_INFO pi ON p.poster_id=pi.auth_id";
$result = mysql_query($sql) or die(mysql_error());
echo mysql_error();
while($row = mysql_fetch_array($result)) {
?>
<tr>
<td><?php echo $row[0]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
</tr>
<?php }
?>
在这种情况下,我没有收到任何警告。