...

View Full Version : row table placement



rachcakes
09-17-2005, 09:38 AM
I want to output my data into a three-column table, but I do not understand where to place my HTML tables or if I need additional coding.

With the following example, the results contain duplicates:


$query = "SELECT * FROM customers";
$result = mysql_query($query);
echo "<table width='600' border='1' cellspacing='4' cellpadding='0'>";
while ($row = mysql_fetch_array($result))
{
extract($row);
echo " <tr>
<td>Hi, my name is $name and I'm $age years old.</td>
<td>Hi, my name is $name and I'm $age years old.</td>
<td>Hi, my name is $name and I'm $age years old.</td>
</tr>"; }
echo "</table>";

// Desired Table Format
+--------+--------+--------+
+--------+--------+--------+
+--------+--------+--------+

devinemke
09-17-2005, 10:38 PM
$result = mysql_query('SELECT * FROM customers') or exit(mysql_error());
while ($row = mysql_fetch_assoc($result)) {$array[] = $row;}
$chunks = array_chunk($array, 3);

echo '<table width="600" border="1" cellspacing="4" cellpadding="0">';
foreach ($chunks as $value)
{
echo '<tr>';
foreach ($value as $row) {echo '<td>Hi, my name is ' . $row['name'] . ' and I\'m ' . $row['age'] . ' years old</td>';}
echo '</tr>';
}
echo '</table>';



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum