Using php to count rows in mysql database? -
i trying count rows demos table got error
catchable fatal error: object of class mysqli_result not converted string in c:\xampp\htdocs\working_scripts\test_2.php on line 8
php code is:
<?php $con=mysqli_connect("localhost","root","","test"); if (mysqli_connect_errno()) { echo"error connecting database". mysqli_connect_error(); } $comment_counter=mysqli_query($con,"select count(*) total demos"); echo $comment_counter; ?>
you have use mysqli_fetch_array
<?php $con = mysqli_connect("localhost","root","","test"); if (mysqli_connect_errno()) { echo"error connecting database". mysqli_connect_error(); } $result = mysqli_query($con, "select count(*) total demos"); if($row = mysqli_fetch_array($result)) { echo $row["total"]; } ?>
Comments
Post a Comment