0
How best to add or show the amount of items in a mysql table using php.
For when I run this code the following error appears:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in H:\Web\root\index.php on line 89
$mysql_connection = mysql_connect($web_host, $web_user, $web_pass);
$mysql_connection_from_db = mysql_select_db($web_db);
$command_ = "SELECT COUNT(`usr_id`) FROM `app_users`";
$mysql_query = mysql_query($command_);
$num = mysql_num_rows($mysql_query);
if(0 == $num) { $PESSOAS = 0; }
else{
while($row = mysql_fetch_assoc($mysql_query))
{
$PESSOAS = $PESSOAS + 1;
}
}
Line 89:
$num = mysql_num_rows($mysql_query);
NOTE: The goal is that the user click to participate and he add a name any more an id in the table and when loading the page the php system shows how many items there are in that table, or in the case, $PESSOAS
, determining the number of participants.
but mysqli is the same as mysql? or a different sql language?
– FRNathan13
It is the same as mysql (http://php.net/manual/en/function.mysqli-connect.php)
– Jeferson Assis
OK I’ll try! : )
– FRNathan13
Oops! Keeps the same mysql_fetch_assoc() expects Parameter 1 to be Resource, Boolean Given in H: Web root index.php on line 86
– FRNathan13
I already switched to mysqli
– FRNathan13
Jeferson Assis I want to make this system equal to stackoverflow when a user opens a question here on the site, shows the number of views understood? but when a user registers on the site it appears how many users are registered.
– FRNathan13
Got it, when you run this query directly in the database returns some data? At this link has an example of how to do the query, but in your will not need the
while()
you can take it straight as I showed in the answer– Jeferson Assis
Look when I run on phpmyadmin it returns me a table indicating the quantity. ex:

-------------------<br>
+-- COUNT --+<br>
------------------<br>
1
– FRNathan13
Oops, when I use mysqli_query the following appears: Warning: mysqli_query() expects Parameter 1 to be mysqli, Boolean Given in H: Web root index.php on line 86 Warning: mysql_fetch_assoc() expects Parameter 1 to be Resource, null Given in H: Web root index.php on line 86
– FRNathan13
one more appeared when I hosted the files in the cloud... Warning: mysql_fetch_assoc(): supplied argument is not a Valid Mysql result Resource in /home/a1478344/public_html/Warface/index.php on line 86
– FRNathan13
Follow this link to the demonstration : http://brasilr2.net76.net/warface/
– FRNathan13
Look I tried to run this and only appears the number 1: $PEOPLE = mysqli_num_rows( mysqli_query( $mysql_connection ,$command_ ));
– FRNathan13