Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-22-2012, 05:13 PM   PM User | #1
agentedx44
New to the CF scene

 
Join Date: Jun 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
agentedx44 is an unknown quantity at this point
[Help]Dynamic Grid in three column

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>
agentedx44 is offline   Reply With Quote
Old 11-22-2012, 05:36 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Upload those images here, my barracuda blocks the site as spyware.
You'll need to translate that error into english as well. I haven't a clue if its a PHP error, but since there is no additional reliance here on external scripts, that would indicate it is a PHP error.
Adding a column is simple, that's a simple <td> added in. Until you upload those images here I can't tell you what you are looking to do; these two scripts are independent on the data they show, so I cannot logically determine what relationship they have to create a third column.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:03 AM.


Advertisement
Log in to turn off these ads.