0

页面在这里:http ://www.arkmediainc.com/ark20test/ark20test/portfolio.php

$result = mysql_query(
    "SELECT * FROM foliobro WHERE itemid >= ".$startid." LIMIT 9"
);

while($row = mysql_fetch_array($result))
{

     $itemid = $row['itemid'];
     $thumb_desc = $row['thumb_desc'];
     $title = $row['title'];
     $category = $row['category'];
     ...
}

我得到这个错误代码:

Warning: mysql_fetch_array() expects parameter 1 to be resource, 
boolean given in /home/arkmedia/public_html/ark20test/ark20test/portfolio.php 
on line 49

49 号线实际上就是那条while($row = mysql_fetch_array($result))线。

我正在尝试获得以下 9 个结果,或者(id 从 1-11,未来扩展)1-9,或者 10-11+ 我的查询出了什么问题,因为我怀疑查询运行不正常。该查询直接来自 phpMyAdmin,所以我不明白为什么它不起作用。

4

3 回答 3

3

将您的代码更改为:

$result = mysql_query("SELECT * FROM foliobro WHERE itemid >= ".$startid." LIMIT 9");

if (!$result) {
    die(mysql_error());
}

您的查询失败,并且您将无效结果传递给mysql_fetch_array.

检查右侧边栏是否有重复的问题。

于 2012-07-24T02:54:51.987 回答
1

来自 PHP 文档:

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning 
resultset, mysql_query() returns a resource on success, or FALSE on error.

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc,
mysql_query() returns TRUE on success or FALSE on error.

The returned result resource should be passed to mysql_fetch_array(), and
other functions for dealing with result tables, to access the returned data.

Use mysql_num_rows() to find out how many rows were returned for a SELECT
statement or mysql_affected_rows() to find out how many rows were affected 
by a DELETE, INSERT, REPLACE, or UPDATE statement.

mysql_query() will also fail and return FALSE if the user does not have 
permission to access the table(s) referenced by the query.

因此,当您收到错误时,它会返回 false,这可能是 SQL 错误,但鉴于查询的简单性,这似乎不太可能,因此我会尝试确保您的权限设置正确。

顺便说一句,请不要使用 mysql_*,使用 PDO 或 mysqli。mysql_* 已弃用。

于 2012-07-24T02:57:07.793 回答
0

如果没有更多信息,我的猜测是您的$startid变量在您运行查询时为空 - 或者您输入了表名。

运行这个:

$sql = "SELECT * FROM foliobro WHERE itemid >= ".$startid." LIMIT 9;";
echo $sql;
$result = mysql_query($sql);

并查看您在运行查询时是否定义了变量/不为空

于 2012-07-24T02:56:54.767 回答