0

I want to make a counter on my home page that goes down with each registration. I am trying to count the number of registered users by id. I put a "?" because I do not know anymore what to put there... I would like to know how to make this work.

include 'config.inc.php';  
    $max = 1000;
    $result = mysqli_query($mysqli, "SELECT COUNT(*) as aantal FROM aanmeldingen WHERE id ='?"); while($row = mysqli_fetch_array($result)); $aantal = $row['id'];
               
                echo "<h2>Er zijn nog ".($max - $aantal)." plaatsen beschikbaar.</h2>"
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • I'm not sure I understand - surely the `id` is unique? The name suggests it would be the identifier, so if you specify that in the query, you'll only retrieve one. If you want a total number of rows in that table, just lose the WHERE clause altogether and retrieve the count of ids. – droopsnoot Jun 09 '21 at 07:57
  • @droopsnoot only 1000 people can register. and I want to show a countdown on my index where you can see how many entries there are left. So I tried to do the amount of possible registrations minus the amount of entries that exist in the database. I tried loosing the Where clause and the count still stays at 1000 – david bog Jun 09 '21 at 08:09
  • @davidbog this link might help you out [PHP count registered users](https://stackoverflow.com/questions/45308822/php-count-registered-users). On a side note I would create a stored procedure and call that, instead of using raw SQL in your code. Also you might want to look into in [PHP PDO](https://www.phptutorial.net/php-pdo/) in PHP, as apparently that's the recommended way of working with PHP data objects – Tim Kruger Jun 09 '21 at 08:18
  • Your `while()` loop has a syntax problem - the variable is assigned after the end of the loop, not inside it, so it won't contain any value as it's written. – droopsnoot Jun 09 '21 at 17:08

0 Answers0