Forum Moderators: coopster
how do i get it so the results to go into the html table like so:
_____________________
¦_01_¦_02_¦_03_¦_04_¦
¦_05_¦_06_¦_07_¦_08_¦
¦_09_¦_10_¦_11_¦_12_¦
thanks for any and all help!
//get the total number of elements at the array
$total = count($data);
//start a loop by 4 (to have 4 columns)
for($i = 0; $i <= $total; $i+=4){
//first column index
$a = $i;
$b = $i + 1;
$c = $i + 2;
$d = $i + 3;
echo "<tr>";
echo "<td>$data[$a]</td>";
echo "<td>$data[$b]</td>";
echo "<td>$data[$c]</td>";
echo "<td>$data[$d]</td>";
echo "</tr>";
}
especially with :
//first column index
$a = $i;
$b = $i + 1;
$c = $i + 2;
$d = $i + 3;
if i dont know exactly how many there will be, how will i know what to put as the increasing variable? ie. $i+ 1, $i + 2, $i + 3, $i + 4...
the results im getting are different products from my online store with upwards of 30 to 40+ results easy.
the only thing that is "known" is your requirement for 4 columns (note the "for" loop increment) and the only thing i see missing is how to fill incomplete rows.
if you have variable column width requirements then you should specify that as well in your problem statement.
<?php
$dbh=mysql_connect ("localhost", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dos_mydb");$result = mysql_query("SELECT * FROM person ");
?>
<table border="1" cellspacing="1" cellpadding="1">
<tr>
<?php
$i = 0;
$entries = mysql_fetch_array($result);
foreach($entries as $data)
{
echo "<td>".$data[FirstName]."</td>";
$i++;if($i == 4)
{
echo "</tr><tr>";
$i = 0;
}
}mysql_close($dbh);
?>
</tr>
</table>