Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result警告:mysql_num_rows():提供的参数不是一个有效的MySQL结果资源
我得到下面的错误消息上下面的代码(其是在查询的末尾):
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ../view-ind-order.php on line 28
此脚本应该检索订单(从列出订单表中所有order_id行的页面),订单内容,订购的用户以及产品信息。我认为我得到的错误是订单中有多个产品的位置,但我无法完全明白我要出错的地方。 (头部有一个会话启动命令)
<?php
$page_title = 'Order';
include ('./includes/header.html');
if ((isset($_GET['id'])) && (is_numeric($_GET['id'])))
{
$id = $_GET['id'];
} elseif ((isset($_POST['id'])) && (is_numeric($_POST['id'])))
{
$id = $_POST['id'];
} else {
echo 'This page has been accessed in error';
include ('./includes/header.html');
exit();
}
require_once ('mydatabase.php');
$query = "SELECT us.users_id, us.users_first_name, us.users_surname, us.users_business,
ord.order_id, ord.users_id, ord.total, ord.order_date,
oc.oc_id, oc.order_id, oc.products_id, oc.quantity, oc.price
prd.products_id, prd.products_name, prd.price
FROM users AS us, orders AS ord, order_contents AS oc, products AS prd
WHERE ord.order_id=$id
AND us.users_id = ord.users_id
AND ord.order_id = oc.order_id
AND oc.products_id = prd.products_id
";
$result = @mysql_query ($query);
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_array ($result, MYSQL_NUM);
echo '
<table>
<tr>
<td><strong>Name:</strong></td>
<td>' . $row[1] . ' ' . $row[2] . '</td>
</tr>
<tr>
<td><strong>Business Name</strong></td>
<td>' . $row[4] . '</td>
</tr>
<tr>
<td><strong>Total:</strong></td>
<td>' . $row[7] . '</td>
</tr>
<tr>
<td><strong>Quantity</strong></td>
<td>' . $row[12] . '</td>
</tr>
<tr>
<td><strong>Product:</strong></td>
<td>' . $row[15] . '</td>
</tr>
<tr>
<td><strong>Price:</strong></td>
<td>' . $row[13] . '</td>
</tr>
</table>
';
} else {
echo '<h1 id="mainhead">Page Error</h1>
<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
}
mysql_close();
include ('./includes/footer.html');
?>
这可能意味着您的mySQL查询中有错误。将@ mysql_query($ query);'行更改为'@mysql_query($ query)或die(mysql_error());' – 2011-05-19 13:41:58
您的SELECT语句(变量$ query)可能有错误。尝试隔离select语句,像'$ result = mysql_query($ query)或者die(mysql_error());'来找出它有什么问题。 – Bjoern 2011-05-19 13:44:27