mysql_num_row从php函数返回0值

时间:2014-06-17 15:07:08

标签: php mysql

我的script.php中有这个功能 $电子邮件= $ _ SESSION [ 'CSPA'] [ '电子邮件'];

    function getit()
    {
      $get_pendingsupport=mysql_query("select
    cus.email,
    datetime,
    s.service_type,
    subject,
    support_id,
    status,
    u.urgency
    from tbl_client_support c
    inner join tbl_client_service s on c.service_id=s.service_id
    inner join customer_reg cus on c.customer_reg_id=cus.id
    inner join tbl_client_urgency u on c.urgency_id=u.urgency_id

    where status='open'
    and cus.email='$email';

    ") or  die(mysql_error());

     return mysql_num_rows($get_pendingsupport) ;
    }
 that my function and am calling it like this in home.php

    但它返回0作为值 但是当我把它带回home.php时没关系 请问可能是错的

2 个答案:

答案 0 :(得分:1)

返回零,因为返回零行。为什么?因为您从未将$email传递给您的函数,所以它不适用于您的查询。由于它在WHERE子句中使用,因此您的查询不会返回您认为它所执行的行,因为没有行的状态为" Open"和一个空的客户电子邮件字段。

您可以通过将该变量传递给您的函数来解决此问题:

function getit($email)
{

当你打电话时:

$num_rows = getit($email);

答案 1 :(得分:0)

您没有将$ email传递给查询。试试这个:

function getit($email)
    {
      $get_pendingsupport=mysql_query("select
    cus.email,
    datetime,
    s.service_type,
    subject,
    support_id,
    status,
    u.urgency
    from tbl_client_support c
    inner join tbl_client_service s on c.service_id=s.service_id
    inner join customer_reg cus on c.customer_reg_id=cus.id
    inner join tbl_client_urgency u on c.urgency_id=u.urgency_id

    where status='open'
    and cus.email='$email';

    ") or  die(mysql_error());

     return mysql_num_rows($get_pendingsupport) ;
    }