How to count no of rows in mysql table?

Count No of rows

$sql="SELECT * FROM admin_info WHERE user_id='$myuserid' and password='$mypassword'";
$result = mysqli_query($con,$sql);
$count = mysqli_num_rows($result);
if($count==1)
{
echo "ok";
}
else
{
echo "null";
}

Example

$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname";

if ($result=mysqli_query($con,$sql))
{
// Return the number of rows in result set
$rowcount=mysqli_num_rows($result);
printf("Result set has %d rows.\n",$rowcount);
// Free result set
mysqli_free_result($result);
}

mysqli_close($con);





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here


Ittutorial