Reputation: 97
i have this function in my script.php $email=$_SESSION['cspa']['email'];
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
but it returning 0 as the value but when i bring it to home.php it's okay please what could be wrong
Upvotes: 0
Views: 33
Reputation: 4391
You are not passing the $email to the query. Try this:
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) ;
}
Upvotes: 0
Reputation: 219894
It returns zero because zero rows are being returned. Why? Because you never pass $email
to your function so it is not available to your query. Since it is used in your WHERE
clause your query doesn't return the rows you think it does as no rows have a status of "Open" and an empty customer email field.
You can solve this by passing that variable to your function:
function getit($email)
{
and when you call it:
$num_rows = getit($email);
Upvotes: 1