-1

好的,我有这个代码:

//this is the hi.php//
<?php
//highlight items//
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("juliver", $con);

$result = mysql_query("SELECT * FROM hi WHERE pp='2'");

$hi = "";

while($row = mysql_fetch_array($result)) //<--- this is the line 13//
  {
  $hi .= "<div id='hicontainer'><a id='download_now' class='imgx' href='#?w=700' rel='popup'><img src='".$row['name']."' />";
  $hi .= "<p>".$row['title']."</p>";
  $hi .= "<a href='#?w=700' id='".$row['id']."' rel='popup' class='imgx'>View full</a>    </div>";
  }

//Lots of lots of code here I just specified those code which in error.//

mysql_close($con);

?>

这是我要实际显示输出的地方。

<td>
<!--highlight items-->
<div id="tbtitle">
<img src="Images/galleryicon.png"/><p>Highlight items</p>
</div>
<div id="tblgal">
<? echo $hi; ?>
</div>
</td>

但我收到一条错误消息:“警告:mysql_fetch_array() 期望参数 1 是资源,布尔值在第 13 行的 C:\xampp\htdocs\madeinusa\hi.php 中给出。”

拜托,我坚持这个。先感谢您。

4

6 回答 6

1

$result有一个布尔值 - 可能是因为您的查询失败。

在尝试使用它之前,您应该验证结果。

查询后,您可以执行以下操作来查看查询失败的原因:

if(!$result)
  exit(mysql_error());
于 2012-04-04T05:34:44.597 回答
1

或者,更简单地说,您可以使用

$result = mysql_query("SELECT * FROM hi WHERE pp='2'") or die(mysql_error());

于 2012-04-04T05:52:55.113 回答
0

检查这一点:

mysql_connect("localhost","username","password");
于 2012-04-04T06:22:21.233 回答
0

首先,您应该在代码中使用适当的异常处理。线后

$result = mysql_query("SELECT * FROM hi WHERE pp='2'");

您应该检查它是否返回资源ID或任何错误

if(!$result){
    // if you use try-catch, then use
   throw new Exception(mysql_error());
   // Or you can use
   die(mysql_error());
}else{
     while($row = mysql_fetch_array($result)) //<--- this is the line 13//
     {
        $hi .= "<div id='hicontainer'><a id='download_now' class='imgx' href='#?w=700'     rel='popup'><img src='".$row['name']."' />";
        $hi .= "<p>".$row['title']."</p>";
        $hi .= "<a href='#?w=700' id='".$row['id']."' rel='popup' class='imgx'>View    full</a>    </div>";
     }

}    
于 2012-04-04T06:23:35.230 回答
-1

您的查询可能有错误"SELECT * FROM hi WHERE pp='2'"
尝试直接在 mysql 中执行该查询,看看会发生什么。确保表名和列的拼写正确。

此外,尝试在反引号 ` 字符中引用表名和列,以避免意外使用 MySQL 保留字。

于 2012-04-04T04:50:00.213 回答
-1

"SELECT * FROM hi WHERE pp='2'" 查询可能返回 false 表示没有完整填写查询的记录。尝试 echo mysql_num_rows($result); 为了知道没有返回查询的行。

于 2012-04-04T05:40:49.097 回答