PDA

View Full Version : New row once you get to a certain number of elements


Silverwolf
Wed 5th Nov '03, 5:51pm
As the title suggests, I'm trying to figure out how to make a new row (in a table) once you get to a certain number of things. For example, say I had to pull 30 items out of the database, wanted them each in a cell, and wanted it to make a new row at the 15th cell. I have this feeling I'm missing something ridiculously obvious, but I can't seem to figure it out. Can anyone help? Thanks :)

- Silver

Chroder
Wed 5th Nov '03, 6:52pm
Well, you use a counter to count up each time.

// ....
$x = 1;
while($row = mysql_fetch_array($query)) {
if($x == 15) {
echo "</tr><tr>";
$x = 1;
}

echo "<td>$row[mydata]</td>";
$x++;
}

Thats about how I do it :D

Silverwolf
Wed 5th Nov '03, 7:29pm
Works like a charm. Many thanks :D