Heckler Posted August 30, 2009 Share Posted August 30, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/172438-counting-number-of-users-registered/ Share on other sites More sharing options...
.josh Posted August 30, 2009 Share Posted August 30, 2009 you don't need that WHERE username in there. Quote Link to comment https://forums.phpfreaks.com/topic/172438-counting-number-of-users-registered/#findComment-909115 Share on other sites More sharing options...
Heckler Posted August 30, 2009 Author Share Posted August 30, 2009 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)! Quote Link to comment https://forums.phpfreaks.com/topic/172438-counting-number-of-users-registered/#findComment-909123 Share on other sites More sharing options...
Heckler Posted August 30, 2009 Author Share Posted August 30, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/172438-counting-number-of-users-registered/#findComment-909126 Share on other sites More sharing options...
.josh Posted August 30, 2009 Share Posted August 30, 2009 right. that's the number of rows returned. you need to use something like current_field like $slotstaken->current_field; Quote Link to comment https://forums.phpfreaks.com/topic/172438-counting-number-of-users-registered/#findComment-909129 Share on other sites More sharing options...
Heckler Posted August 30, 2009 Author Share Posted August 30, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/172438-counting-number-of-users-registered/#findComment-909131 Share on other sites More sharing options...
fenway Posted September 7, 2009 Share Posted September 7, 2009 What are you trying to do again? Quote Link to comment https://forums.phpfreaks.com/topic/172438-counting-number-of-users-registered/#findComment-914136 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.