php - Count MySql database rows with field value = '1' -


i'm trying count number of rows in database field 'level' equal '1'. have set count fields, see code below.

$result = mysql_query("select count(1) username"); $row = mysql_fetch_array($result); $total = $row[0]; 

now adapt select field level = 1 in database.

i have database connection setup , working fine.

i did try code gettign nowhere.

$admins = mysql_query("select count(1) level='1'"); $totaladmins = mysql_fetch_array($admins); $totaladmins = $admins[0]; 

once number of rows have been calculated displayed users through following code

<h4><?php echo $total?> users registered</h4> 

any supper appreciated.

there problem you're having because forgot include table select from. instead of:

select count(1) level='1'; 

your query should be:

select count(1) username level='1'; 

hopefully fixes problem. :)


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -