Jump to content

Counting number of users registered?!


Heckler

Recommended Posts

I am now on my 6th hour of trying to figure out how to do this.  I've searched the web for about the last hour and have tried a numerous amount of ways to try and figure out how exactly I'm suppose to get this thing to work and should also note I am still learning php/mysql.

 

Here is my terrible code.  I've looked at a lot of code claiming to do this, but I cannot get it to work.  I am using Xampp on a Vista machine.


<?php

$dbc = mysqli_connect('localhost', 'username', 'pass', 'league_db')

or die('error connecting to MySQL server.');

 

$result = mysqli_query($dbc, "SELECT COUNT(*) FROM reg_info WHERE username")

 

?>


 

Looking back at my code that i've been experimenting with it would be a disaster for me to copy/paste it right into here.  I feel that my confusion is coming from the COUNT() function and then actually getting the array that the $query pulls to be a single digit.

 

The whole reason for this is so I can notify users of the # of slots taken out of the # of slots available.  32 in my precise case.  I started this little adventure when I thought it would be a good addition but I had no idea it would drive me this mad. 

 

Any help or direction is greatly appreciated.  :shrug:

Link to comment
https://forums.phpfreaks.com/topic/172438-counting-number-of-users-registered/
Share on other sites

Ok.

 

This is the error I get now:

Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\Server\xampp\webdav\numregistered.php on line 14

 

Here is my code:


<?php

$dbc = mysqli_connect('localhost', 'username', 'pass', 'league_db')

or die('error connecting to MySQL server.');

$query = "SELECT COUNT(*) FROM reg_info";

$slotstaken = mysqli_query($dbc, $query);

 

echo $slotstaken; //THIS IS LINE 14

?>


It would appear my issue would be obvious, but I am unsure of how I am to convert $slotstaken into a single number which would reflect the number users I currently have.

 

Thanks again (ahead of time)!

OK!

 

I'm slowly (I think) figuring it out.

 

I've added the following:


<?php

//Creates connection to database

$dbc = mysqli_connect('localhost', 'username', 'pass', 'league_db')

or die('error connecting to MySQL server.');

 

$query = "SELECT COUNT(*) FROM reg_info";

 

$slotstaken = mysqli_query($dbc, $query);

 

$slots = $slotstaken->num_rows;

 

//echo $slotstaken; LINE 14

 

echo $slots;

?>


 

My issue now is that it is only returning "1" when I have more users registered.

 

right. that's the number of rows returned.  you need to use something like current_field

 

like $slotstaken->current_field;

 

So would I loop the query and find out the number of users after it is done looping and pulls the last entry as the current_field?

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.