You are on page 1of 1

<?

php
// Include database connection
include_once 'connect_to_mysql.php';
// SQL query to interact with info from our database
$sql = mysql_query("SELECT id, member_name FROM member_table ORDER BY id DESC LI
MIT 15");
$i = 0;
// Establish the output variable
$dyn_table = '<table border="1" cellpadding="10">';
while($row = mysql_fetch_array($sql)){

$id = $row["id"];
$member_name = $row["member_name"];

if ($i % 3 == 0) { // if $i is divisible by our target number (in this case
"3")
$dyn_table .= '<tr><td>' . $member_name . '</td>';
} else {
$dyn_table .= '<td>' . $member_name . '</td>';
}
$i++;
}
$dyn_table .= '</tr></table>';
?>
<html>
<body>
<h3>Dynamic PHP Grid Layout From a MySQL Result Set</h3>
<?php echo $dyn_table; ?>
</body>
</html>

You might also like