I'm trying to count the number of rows in my database with the field 'Level' equal to '1'. I already have this set up to count the fields, see code below.
$result = mysql_query("select count(1) FROM username");
$row = mysql_fetch_array($result);
$total = $row[0];
Now I would like to adapt this to only select field where the Level = 1 in the database.
I already have the database connection setup and its working fine.
I did try this code but was gettign nowhere.
$admins = mysql_query("select count(1) FROM WHERE Level='1'");
$totaladmins = mysql_fetch_array($admins);
$totaladmins = $admins[0];
Once the number of rows have been calculated it is displayed to the users through the following code
<h4><?php echo $total?> Users registered</h4>
Any help is supper appreciated.
There problem you're having is just because you forgot to include which table to select from. Instead of:
SELECT count(1) FROM WHERE Level='1';
Your query should be:
SELECT count(1) FROM username WHERE Level='1';
Hopefully this fixes your problem. :)
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.