CREATE TABLE IF NOT EXISTS `members` ( `id` int(11) NOT NULL AUTO_INCREMENT, `fname` varchar(100) NOT NULL, `lname` varchar(100) NOT NULL, `age` int(5) NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
<?php /* Database config */ $db_host = 'localhost'; $db_user = 'root'; $db_pass = ''; $db_database = 'pdo_ret'; /* End config */ $db = new PDO('mysql:host='.$db_host.';dbname='.$db_database, $db_user, $db_pass); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); ?>
<table border="1" cellspacing="0" cellpadding="2" > <thead> <tr> <th> First Name </th> <th> Last Name </th> <th> Age </th> </tr> </thead> <tbody> <?php include('connect.php'); $result = $db->prepare("SELECT * FROM members ORDER BY id DESC"); $result->execute(); for($i=0; $row = $result->fetch(); $i++){ ?> <tr class="record"> <td><?php echo $row['fname']; ?></td> <td><?php echo $row['lname']; ?></td> <td><?php echo $row['age']; ?></td> </tr> <?php } ?> </tbody> </table>