Cacoon
Cacoon

Reputation: 2538

Count the number of rows in one table with PHP

I'm having some problems with counting the size of a table of my table.

I want to know how many 'inputs'? I guess are in there so I can present the total number of 'users' on my admin panel.

I tried looking at another question and here is what I created out of it.

I am not the best with PHP, I was wondering if anyone could answer my question.

$connect = mysql_connect('****.com','****User','****Pass') or die("Error");
mysql_select_db('****Database') or die("Error");
$data = "SELECT COUNT(`ID`) AS num FROM `UserDB`";
$row = mysql_fetch_assoc($data);
$numUsers = $row['num'];
mysql_query($data,$connect);
mysql_close($connect);
echo $numUsers;

Upvotes: 1

Views: 1662

Answers (2)

Kai Qing
Kai Qing

Reputation: 18843

THe only help I can give you is showing you what I mean by swap...

$connect = mysql_connect('****.com','****User','****Pass') or die("Error");
mysql_select_db('****Database') or die("Error");
$data = mysql_query("SELECT COUNT(`ID`) AS num FROM `UserDB`");
$row = mysql_fetch_assoc($data);
$numUsers = $row['num'];
mysql_close($connect);
echo $numUsers;

As for how to manage whatever free host, I can only suggest you contact them and ask how to update the file in question, assuming that was your point of the comment. If not, feel free to clarify.

Upvotes: 0

echo_Me
echo_Me

Reputation: 37243

change your query to this

   $data = mysql_query("SELECT COUNT(`ID`) AS num FROM `UserDB`");

OBS: please consider to learn mysqli or PDO

Upvotes: 1

Related Questions