查询计数空白

时间:2014-12-14 17:54:18

标签: php mysql

我正在尝试查询计算它找到的行数,我得到的是一个警告: 警告:mysql_num_rows()要求参数1为资源,布尔值在第58行的D:\ xampp2 \ htdocs \ birth \ email2.php中给出

function newMessages( $profile_id )
    {
        global $prefix;

        $INITIATOR_FLAG = 1;
        $INTERLOCUTOR_FLAG = 2;

        $newMessageCountCache = array();

        define('TBL_MAILBOX_CONVERSATION', $prefix.'mailbox_conversation');
        define('TBL_MAILBOX_MESSAGE', $prefix.'mailbox_message');


        $query = mysql_query("SELECT DISTINCT `c`.`conversation_id`
            FROM `".TBL_MAILBOX_CONVERSATION."` AS `c`
            LEFT JOIN `".TBL_MAILBOX_MESSAGE."` AS `m` ON (`c`.`conversation_id` = `m`.`conversation_id`)
            WHERE (`initiator_id`=".$profile_id."  OR `interlocutor_id`=".$profile_id.")
            AND (`bm_deleted` IN(0,".$INTERLOCUTOR_FLAG.") AND `initiator_id`=".$profile_id." OR `bm_deleted` IN(0,".$INITIATOR_FLAG.") AND `interlocutor_id`=".$profile_id.")
            AND (`bm_read` IN(0,".$INTERLOCUTOR_FLAG.") AND `initiator_id`=".$profile_id." OR `bm_read` IN(0,".$INITIATOR_FLAG.") AND `interlocutor_id`=".$profile_id.") AND `m`.`recipient_id`=".$profile_id."
        ");

        $newMessageCountCache[$profile_id] = mysql_num_rows($query);
        return $newMessageCountCache[$profile_id];
    }

mysql_close($cxn);

$emails  = newMessages( $profile_id );
echo $emails;

第58行是:$ newMessageCountCache [$ profile_id] = mysql_num_rows($ query);

不确定我在这里缺少什么。任何帮助都将非常感激我已经挖了sql肯定不是我的强项。

2 个答案:

答案 0 :(得分:0)

$query = mysql_query("
SELECT DISTINCT `c`.`conversation_id`
FROM `".TBL_MAILBOX_CONVERSATION."` AS `c`
LEFT JOIN `".TBL_MAILBOX_MESSAGE."` AS `m` 
ON 
(`c`.`conversation_id` = `m`.`conversation_id`)
WHERE 
(`initiator_id`=".$profile_id."  OR `interlocutor_id`=".$profile_id.")
AND 
(`bm_deleted` IN(0,".$INTERLOCUTOR_FLAG.") AND `initiator_id`=".$profile_id.") OR 
(`bm_deleted` IN(0,".$INITIATOR_FLAG.") AND `interlocutor_id`=".$profile_id.")
AND 
(`bm_read` IN(0,".$INTERLOCUTOR_FLAG.") AND `initiator_id`=".$profile_id.") OR 
(`bm_read` IN(0,".$INITIATOR_FLAG.") AND `interlocutor_id`=".$profile_id.") 
AND `m`.`recipient_id`=".$profile_id." 
");

$newMessageCountCache[$profile_id] = mysql_num_rows($query);

答案 1 :(得分:0)

// Add this line after $query = ...
$result = mysql_query($query);
// Now count rows in result
$newMessageCountCache[$profile_id] = mysql_num_rows($result);
return $newMessageCountCache[$profile_id];