⊗ppPmDBGC 379 of 447 menu

Getting Count in PHP

Let's see how to get the counted number in our PHP script, as it's not that simple here.

Let's write the code that counts the number of users:

<?php $query = "SELECT COUNT(*) FROM users"; $res = mysqli_query($link, $query) or die(mysqli_error($link)); $data = mysqli_fetch_assoc($res); ?>

In our case, the count will end up in the variable $data. However, this variable will be an array of the following form:

<?php var_dump($data); // ['COUNT(*)' => 6] ?>

To make the key in this array more beautiful, you can rename our field in the query using the as command:

<?php $query = "SELECT COUNT(*) as count FROM users"; ?>

After such renaming, in the variable $data our count will already be in the key 'count':

<?php var_dump($data); // ['count' => 6] ?>

Count all users with a salary of 300.

Count all users with a salary of 300 or age of 23.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline