Good day, just new in php and really confuse. i have a dynamic Grid below in my screenshot,that is only straight. the codes are working well but i want to put it in 3 columns. so i research about dynamic grid output, My problem is after trying to insert this in my codes,,, it gives me different error.. sa mga mabubuti po ang loob dyan ,, pls guide me to make my images in 3 columns.
current image:
my desired output:
Here the codes in my index.php
Code:
<?php
// Run a select query to get my letest 6 items
// Connect to the MySQL database
include "includes/connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM tbl_products ORDER BY date_added DESC LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="418" border="2" cellpadding="6">
<tr>
<td width="124" valign="top"><a href="product.php?id=' . $id . '"><img src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="120" height="121" /></a></td>
<td width="256" valign="top">' . $product_name . '<br />
$' . $price . '<br />
<a href="product.php?id=' . $id . '">View Product Details</a></td>
</tr>
</table>';
}
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>
code that i want to insert:
Code:
<?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 LIMIT 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>