View Single Post
  #1 (permalink)  
Old 08-09-06, 01:02 PM
Rahil Rahil is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Toronto, Ontario, Canada
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Red face Creating a dynamic table with 3 columns per row

Hi guys,

I have this very frustrating problem

I'm trying to make a dynamic table with only 3 columns per row. So every 3 items, I need a new row.

This code works fine, in fact, some may benefit from it:

PHP Code:

<?php


echo "<pre>";

$input_array = array('1''2''3''4''5''6''7''8');
$input_array array_chunk($input_array3true);

echo 
"<table width=\"500\" border=\"0\" cellspacing=\"5\" cellpadding=\"0\">\n";

foreach (
$input_array as $set) {
    echo 
"<tr>\n";
    foreach (
$set as $key) {
        echo 
"  <td>$key</td>\n";
    }
    echo 
"</tr>\n";
}

echo 
"</table>\n";

echo 
"</pre>";

?>
Now, here is my problem. The array I created above is static. I want a dynamic array that is created from MySQL values. How can I do that? I can provide more details if needed, I'm just not sure what I need to make this happen.

Is there a MySQL function that will do this for me? mysql_fetch_array only fetches an array for one row in the MySQL table unless I loop it. I was thinking I could use PHP's array appending functions.

Please, I would love any help
Reply With Quote