php - create columns from mysql list
Posted
by
user271619
on Stack Overflow
See other posts from Stack Overflow
or by user271619
Published on 2011-01-16T07:48:52Z
Indexed on
2011/01/16
7:53 UTC
Read the original article
Hit count: 225
I have a long list generated from a simple mysql select query.
Currently (shown in the code below) I am simply creating list of table rows with each record. So, nothing complicated.
However, I want to divide it into more than one column, depending on the number of returned results. I've been wrapping my brain around how to count this in the php, and I'm not getting the results I need.
<table>
<?
$query = mysql_query("SELECT * FROM `sometable`");
while($rows = mysql_fetch_array($query)){
?>
<tr>
<td><?php echo $rows['someRecord']; ?></td>
</tr>
<? } ?>
</table>
Obviously there's one column generated. So if the records returned reach 10, then I want to create a new column. In other words, if the returned results are 12, I have 2 columns. If I have 22 results, I'll have 3 columns, and so on.
© Stack Overflow or respective owner