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
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)!

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.