简体   繁体   中英

I can't get a record when using COUNT in php

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'];  

First of all your concatenation is incorrect, it should be

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

Secondly, instead of using count() you can use mysql_num_rows()

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

Note: mysql_() is deprecated, consider using mysqli_() or PDO instead

正确的SQL:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM