0

I want to count all user records and display them in tables, I am trying this code code, It displays the record for one user only, I want to display records from all users.

$u=$_POST['userid'];

$result1 = mysqli_query($con,"SELECT COUNT(user_id) as total FROM table-name where user_id=$u");

echo "<table border='1'>

</tr>

<tr>

<th>User ID</th>

<th>count</th>

</tr>";

while($row = mysqli_fetch_array($result1))
  {
  echo "<tr>";
 echo "<td>" . $u . "</td>";
  echo "<td>" . $row['total'] . "</td>";
   echo "</tr>";
  }
echo "</table>";
}

2 Answers 2

1

Try the following SQL Query:

SELECT `user_id`, COUNT(`user_id`) as `total` FROM `table-name` GROUP BY `user_id`;

Refer to the documentation of the GROUP BY clause.

Sign up to request clarification or add additional context in comments.

Comments

0

Use below:

$result1 = mysqli_query($con,"SELECT COUNT(user_id) as total FROM table-name");

where clause use for filter the data. refer http://www.w3schools.com/sql/sql_where.asp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.