我有一个主键为字段'c_number‘的表。现在我已经在两个表中使用了这个主键作为外键: calls和billing。有人能告诉我为什么这个查询不起作用吗?
$q="select c_number, type, billing.days from calls, billing where calls.c_number=billing.c_number group by c_number";
$r=mysql_query($q);
while($row=mysql_fetch_array($r))
{
echo $row['days'];
}查询不起作用,给我的错误是:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\vas1\b.php on line 61第61行:
while($row=mysql_fetch_array)发布于 2013-06-16 05:03:05
像这样改变你的习惯
$q="select c_number, type, billing.days from calls, billing where calls.c_number=billing.c_number group by c_number";
$r=mysql_query($q);
while($row=mysql_fetch_array($r))
{
echo $row['days'];
}另外,作为建议,请注意文档中的原始MySQL API已被弃用:
此扩展从PHP5.5.0起不再推荐使用,并将在将来删除。相反,应该使用MySQLi或PDO_MySQL扩展。有关更多信息,请参阅MySQL:选择应用程序接口指南和相关常见问题解答。
这里是PDO的docs
发布于 2013-06-16 05:11:18
它会给出错误,因为您没有将结果提供给mysql_fetch_array()函数。
应该是这样的:mysql_fetch_array($r)
还要考虑在values in sql语句中使用引号。
您可以在this link中找到mysql_fetch_array()的几个示例。
https://stackoverflow.com/questions/17127840
复制相似问题