0

I am trying to show a count of all applications stored in a database with the status of 1.

Here is my UPDATED code:

    $result=mysql_query("SELECT * FROM member ")or die('You need to add an administrator ' );

$counter = mysql_query("SELECT COUNT(*) as personID FROM member where state='1' ");
$row = mysql_fetch_array($result);

    $personID = $row['personID'];

$num = mysql_fetch_array($counter);
$countadmin = $num["personID"];

However this isn't showing anything when I echo `$countadmin'

Can anyone help

4

3 回答 3

0

您在这里有两个选择;

$result = mysql_query("SELECT * FROM `member` WHERE `Status`='1'");
$num_rows = mysql_num_rows($result);

或者

$result = mysql_query("SELECT COUNT(`Status`) FROM `member` WHERE `Status`='1'");
while($row = mysql_fetch_array($result)){
    $Count = $row['count(Status)'];
}
于 2013-11-08T22:19:54.473 回答
0

你可以试试这个

$query = mysql_query("select count(*) from member where state='1'");
if ($query) {
    $count = mysql_result($query, 0, 0);
    echo $count;
}

检查mysql_result并注意Warning顶部。还要确保,该字段state不是status,它令人困惑,您status在问题中提到但state在查询中使用。

此外,不需要以下行来获得count您的第二个query

$result=mysql_query("SELECT * FROM member ")or die('You need to add an administrator ' );

另外,请确保您已连接到数据库并选择它。

于 2013-11-08T22:22:48.077 回答
0

您尝试读出“ID”,但您选择 COUNT 作为“personID”

于 2013-11-08T22:11:56.983 回答