I need to display a “count” of records (rows) in my SQLtable “doctors”. This count must appear on my dashboard page in the below element for total number of doctors
This is index.php for my dashboard page
<?php $con = mysqli_connect("localhost","root","","hospital_db"); $result = mysqli_query($con,"SELECT * FROM doctors"); $rows = mysqli_num_rows($result); $content = '<div class="row"> <div class="col-lg-3 col-xs-6"> <!-- small box --> <div class="small-box bg-aqua"> <div class="inner"> <h3><?php echo '.$rows.';?></h3> <p>Doctors</p> </div> <div class="icon"> <i class="ion ion-bag"></i> </div> <a href="http://localhost/medibed/doctor" class="small-box-footer">View Doctors <i class="fa fa-arrow-circle-right"></i></a> </div> </div> <!-- ./col --> </div>'; include('../master.php'); ?>
Advertisement
Answer
You should use mysqli object in new php version try the following code
Make connection first like
<?php $con = mysqli_connect("localhost","my_user","my_password","my_db"); $result = mysqli_query($con,"SELECT * FROM doctors"); $rows = mysqli_num_rows($result); echo "There are " . $rows . " rows in my table."; $content = '<div class="row"> <div class="col-lg-3 col-xs-6"> <!-- small box --> <div class="small-box bg-aqua"> <div class="inner"> *<h3><?php echo "$rows"; } ?></h3>* <p>Doctors</p> </div> <div class="icon"> <i class="ion ion-bag"></i> </div> <a href="http://localhost/medibed/doctor" class="small-box-footer">View Doctors <i class="fa fa-arrow-circle-right"></i></a> </div> </div> <!-- ./col --> </div>'; include('../master.php'); ?>