stuffradio
01-03-2007, 03:54 AM
I've wanted to know how to do this for a long time...
How do you pull all values from a table and have them display for times in a row.
Example:
Entry1 Entry 2 Entry 3 Entry 4
Entry 5 Entry 6 Entry 7 Entry 8
etc.
juangake
01-03-2007, 08:18 AM
How about creating a table, and then going through all your values?
Your table should end like...
<table border=1>
<tr><td>Entry1</td><td>Entry2<td>Entry3</td><td>Entry4</td></tr>
<tr><td>Entry5</td><td>Entry6<td>Entry7</td><td>Entry8</td></tr>
</table>
If you want specific code... just ask..
Juan
stuffradio
01-03-2007, 02:04 PM
That wouldn't work... I'm trying to get it from a mysql database
ssj4gogeta
01-03-2007, 02:14 PM
You can do
<?php
$array = mysql_fetch_array($sql_query);
?>
<table width="100%" border="0" cellpadding="0">
<?php foreach (array_chunk($array, 4) as $row) { ?>
<tr>
<?php foreach ($row as $item) { ?>
<td align="center"><?=$item['name']?></td>
<?php } ?>
</tr>
<?php } ?>
</table>
maxymizer
01-03-2007, 02:15 PM
$i = 0;
while($row = mysql_fetch_array($query))
{
if($i == 0) echo '<td>';
echo $row['data'];
if($i == 3) { echo '</td>'; $i = 0;}
$i++;
}
That's how it's done.
Xeentech
01-03-2007, 02:33 PM
Shouldn't they be 'tr's, and have 'td's around the $row['data']; that would just put four data's in one TD cell.
stuffradio
01-03-2007, 03:46 PM
it only shows one result. This is what I have:
while ($grid = mysql_fetch_array($get)) {
if ($row == 0) {
echo '<tr>';
echo "<td>$grid[status]</td>";
}
if ($row == 4) {
echo '</td></tr>';
$row = 0;
}
$row++;
}
http://wuensche.ca/battleship
BurakUeda
01-04-2007, 05:24 AM
while ($grid = mysql_fetch_array($get))
{
if ($row == 0)
{
echo '<tr>';
}
echo "<td>".$grid["status"]."</td>";
if ($row == 3)
{
echo '</tr>';
$row = 0;
}
$row++;
}