$result = mysql_query("SELECT COUNT(*) FROM Students;");I need the result to display. But I am not getting the result.
Bạn đang xem: Mysql count
I have tried with the following methods:
mysql_fetch_assoc()mysql_free_result()mysql_fetch_row()But I didn"t succeed khổng lồ display (get) the actual value.


Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
Help us improve our answers.
Xem thêm: Css3 Gradients - Left To Right Gradient Css Code Example
Are the answers below sorted in a way that puts the best answer at or near the top?
You need to alias the aggregate using the as từ khoá in order to gọi it from mysql_fetch_assoc
$result=mysql_query("SELECT count(*) as total from Students");$data=mysql_fetch_assoc($result);echo $data<"total">;


here is the code for showing no of rows in the table with PHP
$sql="select count(*) as total from student_table";$result=mysqli_query($con,$sql);$data=mysqli_fetch_assoc($result);echo $data<"total">;

With mysql v5.7.20, here is how I was able lớn get the row count from a table using PHP v7.0.22:
$query = "select count(*) from bigtable";$qresult = mysqli_query($this->conn, $query);$row = mysqli_fetch_assoc($qresult);$count = $row<"count(*)">;echo $count;The third line will return a structure that looks like this:
array(1) <"count(*)">=>string(4) "1570"In which case the ending echo statement will return:
1570
If you only need the value:
$result = mysql_query("SELECT count(*) from Students;");echo mysql_result($result, 0);
You can as well use this and upgrade to mysqli_ (stop using mysql_* extension...)
$result = mysqli_query($conn, "SELECT COUNT(*) AS `count` FROM `Students`");$row = mysqli_fetch_array($result);$count = $row<"count">;echo $count;
Please start using PDO.
mysql_* is deprecated as of PHP 5.5.0 và will be removed entirely in 7. Let"s make it easier to lớn upgrade & start using it now.
$dbh = new PDO($dsn, $user, $password);$sth = $dbh->prepare("SELECT count(*) as total from Students");$sth->execute();print_r($sth->fetchColumn());
For mysqli users, the code will look like this:
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);$result = $mysqli->query("SELECT COUNT(*) AS Students_count FROM Students")->fetch_array();var_dump($result<"Students_count">);or:
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);$result = $mysqli->query("SELECT COUNT(*) FROM Students")->fetch_array();var_dump($result<0>);
$result = mysql_query("SELECT COUNT(*) AS `count` FROM `Students`");$row = mysql_fetch_assoc($result);$count = $row<"count">;Try this code.
$num_result = mysql_query("SELECT count(*) as total_count from Students ") or exit(mysql_error());$row = mysql_fetch_object($num_result);echo $row->total_count;
$db = new PDO("mysql:host=localhost;dbname=java_db", "root", "pass");$Sql = "SELECT count(*) as `total` FROM users";$stmt = $db->query($Sql);$stmt->execute();$total = $stmt->fetch(PDO::FETCH_ASSOC);print "";print_r($total);print "";Result:

You need to alias the aggregate using the as từ khoá in order to điện thoại tư vấn it from mysqli_fetch_assoc
$result=mysqli_query($conn,"SELECT count(*) as total from Students");$data=mysqli_fetch_assoc($result);echo $data<"total">;
$howmanyuser_query=$conn->query("SELECT COUNT(uno) FROM userentry;"); $howmanyuser=$howmanyuser_query->fetch_array(MYSQLI_NUM); echo $howmanyuser<0>;after the so many hours excellent :)
Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.
Not the answer you're looking for? Browse other questions tagged php mysql count or ask your own question.
Site thiết kế / logo © 2022 Stack Exchange Inc; user contributions licensed under cc by-sa. Rev2022.4.21.42004
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device và disclose information in accordance with our Cookie Policy.