0

i have 2 tables like this

tbl_inbox
-SenderNumber
-Message

tbl_report
-Number
-Name
-Count

actually i want to show how many times these numbers appear in table count, i have try this code,but didn't show anything.
this my code :

$count = mysql_query("SELECT count(SenderNumber) as num FROM tbl_inbox WHERE SenderNumber = ".$data['Number']"");  
$result = mysql_fetch_assoc($count);  
$countresult = $result['num'];  
4

2 回答 2

1

首先你的连接不正确,应该是

...WHERE SenderNumber = ".$data['Number']);

其次,count()您可以使用而不是使用mysql_num_rows()

echo mysql_num_rows($count); //Returns row count

注意:mysql_()已弃用,请考虑使用mysqli_()orPDO 代替

于 2013-10-10T05:45:42.607 回答
0

正确的sql:

$count = mysql_query("SELECT count(SenderNumber) as num FROM tbl_inbox WHERE SenderNumber = ".$data['Number']);  
于 2013-10-10T05:46:35.667 回答