0

How can i count all numbers in 'status' within the lines of 'user_registration'?

this is what i have. it works good, but it just shows the amount of lines within 'user_registration'.

 <?php
    $con = mysql_connect($dbHost, $dbUser, $dbPass );
    mysql_select_db($dbName, $con);
    $res = mysql_query('SELECT Count(*) FROM ' . 'user_registration', $con);
    if ($row = mysql_fetch_array($res, MYSQL_NUM))
    {
       $users = trim($row[0]);
    }
    else
    {
       $users = 'Error';
    }
    ?>

to Show result on website:

<?= $users ?>
Fub Tinzi
  • 11
  • 4
  • 1
    Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). You will also want to [Prevent SQL Injection!](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Nov 18 '14 at 16:30

1 Answers1

3

If I understand your question correctly:

SELECT SUM(status) FROM user_registration

Here more info on MySQL aggregate functions: http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html


P. S. As Jay suggested in comments, consider moving away from mysql_* functions.

Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103