【发布时间】:2011-08-23 16:34:48
【问题描述】:
这是我的代码:
$sql = mysql_query("select c.name, c.address, c.postcode, c.dob, c.mobile, c.email,
count(select * from bookings where b.id_customer = c.id) as purchased, count(select * from bookings where b.the_date > $now) as remaining,
from customers as c, bookings as b
where b.id_customer = c.id
order by c.name asc");
您可以看到我正在尝试做什么,但我不确定如何正确编写此查询。
这是我得到的错误:
警告:mysql_fetch_assoc():提供 参数不是有效的 MySQL 结果 资源
这是我的 mysql_fetch_assoc:
<?php
while ($row = mysql_fetch_assoc($sql))
{
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['mobile']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['purchased']; ?></td>
<td><?php echo $row['remaining']; ?></td>
</tr>
<?php
}
?>
【问题讨论】:
-
从 phpmyadmin 或 CLI 界面执行时是否有效?
-
请说明您是如何完成
mysql_fetch_assoc()查询的。 -
我已将其添加到原帖中...