我在php服务器上使用代码,可以帮助为iphone应用程序创建收藏列表事件。但是,我收到错误说
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/content/10/10898710/html/dealapp/favoriteevent.php on line 6
Warning: Cannot modify header information - headers already sent by (output started at /home/content/10/10898710/html/dealapp/favoriteevent.php:6) in /home/content/10/10898710/html/dealapp/favoriteevent.php on line 13
"favorite event list":"No event favorite"}
我使用的脚本是:
<?php
require_once('config.php'); //cre
$userid = $_REQUEST['userid'];
$selectfavorite = mysql_query("select a.eventid, a.favorite, a.userid, b.* from favoriteevent as a, event as b where a.eventid = b.id and a.userid = '".$userid."'");
$posts = array();
if(mysql_num_rows($selectfavorite)) {
while($post = mysql_fetch_assoc($selectfavorite)) {
$posts[] = $post;
}
header('Content-type: application/json');
echo(json_encode(array('favorite event list'=>$posts)));
} else {
header('Content-type: application/json');
echo (json_encode(array('favorite event list'=>'No event favorite')));
}
?>
如果有人能帮助我,我将不胜感激。
答案 0 :(得分:1)
您应首先检查$ selectFavourite是否为false。如果查询有一些错误,它将返回false。然后你可以继续前进。另外,检查您的查询是否正常。
$selectfavorite = mysql_query("select a.eventid, a.favorite, a.userid, b.* from favoriteevent as a, event as b where a.eventid = b.id and a.userid = '".$userid."'");
if($selectFavourite !== false)
{
}
答案 1 :(得分:0)
您必须传递mysql_num_rows查询结果的资源标识符。
$ result = mysql_query(...); $ numRows = mysql_num_rows($ result);