No ratings yet.

 

 

 

 

 

 

 

 

 

how to get record of field as object from php with mysql

<?php
if ($result = $mysqli->query(“SELECT * FROM user_info ORDER BY id”))
                        {
                                // display records if there are records to display
                                if ($result->num_rows > 0)
                                {
                                        // display records in a table
                                        
                                     echo “<table table-bordered>”;
                                        
                                        // set table headers
                                        echo “<tr><th>ID</th><th>First Name</th><th>Last Name</th><th>Cnic</th><th>Cell no</th><th>Delete the record</th></tr>”;
                                        
                                        while ($row = $result->fetch_object())
                                        {
                                                // set up a row for each record
                                                echo “<tr>”;
                                                echo “<td>” . $row->id . “</td>”;
                                                echo “<td>” . $row->f_name . “</td>”;
                                                echo “<td>” . $row->l_name . “</td>”;
                                                echo “<td>” . $row->cnic . “</td>”;
                                                echo “<td>” . $row->cell_no . “</td>”;
                                                
                                                echo “<td><a href=’delete.php?id=” . $row->id . “‘>Delete</a></td>”;
                                                echo “</tr>”;
                                        }
                                        
                                        echo “</table>”;
                                }
                                // if there are no records in the database, display an alert message
                                else
                                {
                                        echo “No results to display!”;
                                }
                        }
                        // show an error if there is an issue with the database query
                        else
                        {
                                echo “Error: ” . $mysqli->error;
                        }
                        
                        // close database connection
                        $mysqli->close();
                
                ?>

Please rate this