Log in

View Full Version : using While to create rows



Timms
02-15-2013, 06:38 PM
Using a table i am to pull out data from my MySQL data-base, generaly works fine but what i need to do is pull the data out then go on to a new column of the same row but want it to go 3 columns then make a new row, so pull data out tell it has 3 columns with data then go to a new row then do another 3 columns filled out. The current one does 1 column then does a new row so how would i go about doing 3 columns then going to a new row after it has 3? Thanks in advance this is my current set up

<?php
while ($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>".$row["thedate"]."</td>";
echo "</tr>";
}

?>

fastsol1
02-16-2013, 12:30 AM
This is the method that I use


$column = 3;
$rowend = 1;
echo '<table><tr>';
//Run your loop here

while ($row = mysql_fetch_array($query)) {
echo "<td>".$row["thedate"]."</td>";

if ($rowend == $column){ echo "</tr><tr>"; $rowend=0;}
$rowend++;
}
echo '</tr></table>';