October 17, 2018 -
MYSQLI CRUD Series,OOP CRUD,PHP,Programming Notes
No comments
Display Data from Database: MYSQLI CRUD OOP Series
Step 6. Display data from database in index.php
Insert the following codes after
the end </form> tag in index.php
<!--display data from database-->
<table align="center">
<?php
$query_userlevel="SELECT * FROM tbl_userlevel";
$resource_userlevel=mysqli_query($obj->con, $query_userlevel);
Print "<th>ID</th>";
Print "<th>Userlevel Name</th>";
Print "<th>Description</th>";
Print "<th>Action</th>";
while($result_userlevel=$resource_userlevel->fetch_assoc())
{
Print "<tr>";
$ulevel_id = $result_userlevel['ulevel_id'];
Print "<td>". $result_userlevel['ulevel_id']. "</td>";
Print "<td>". $result_userlevel['ulevel_name']. "</td>";
Print "<td>". $result_userlevel['ulevel_desc']. "</td>";
Print "<td>"."<a href ='index.php?edit=$ulevel_id'>"."Edit"."</a>"."</td>";
Print "</tr>";
}
?>
Discussion:
$resource_userlevel=mysqli_query($obj->con, $query_userlevel); This command will pass the data using the database connection and query to variable $resource_userlevel.
while($result_userlevel=$resource_userlevel->fetch_assoc()) This code will pass the associative array to variable $result_userlevel that will be display in a table format.
The table will allow the user to easily edit the record by clicking on Edit link.
0 comments:
Post a Comment
If possible, leave a positive comment. No hate speech or elicit comments. Thank you.