I'm a newbie to this. Hi, i've been trying to display all database records on an html table i still cant think anything out. I only know how to display a predefined number of rows but i need it to display all db records. I know it has to do with some loops but i dont know how to go about it. I wil really appreciate any help to this. Thanks.

Hey Shel,

it's quite simple really :)

So lets say in your database you have 3 columns. customer_name,postcode and mainarea.

What the code below does is create a table with headers (hence the echo <Th>) and then it uses fetch_object() to create objects of each header and display them!

All you have to do then, is style the table :)

            <?PHP

                $tbl_name = '';
                $query = "SELECT * FROM $tbl_name";

                if ($result = $mysqli->query($query)) {

                /* fetch object array */
                echo '<table align="center">';
                echo" <th>Name</th><th>Postcode</th><th>Mainarea</th><th>Expiration date</th>";
                while ($obj = $result->fetch_object()) {

                    echo "<tr><td>".$obj->customer_name."</td><td>".$obj->postcode."</td><td>".$obj->mainarea."</td><td>".$obj->expiration."</td></tr>";
                }
                 echo "</table>";
                /* free result set */
                $result->close();
            }

            /* close connection */
            $mysqli->close();
            ?>
commented: Nice AND MySQLi ! +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.