The Little Guy Posted July 20, 2009 Share Posted July 20, 2009 I have a page that displays items according to values in the database. So... I have a column in the database called 'column'. Column tells what column to place the item in. I am having problems creating the columns on the page. $sql = mysql_query("SELECT * FROM userWidgets u LEFT JOIN widgets w ON (u.widget = w.id) WHERE owner = '$_id' ORDER BY `column`, `row`"); while($row = mysql_fetch_array($sql)){ } I am not sure how to code within the loop to make column one and column two. Both columns can contain 1 or more items, so any help? Quote Link to comment Share on other sites More sharing options...
gijew Posted July 20, 2009 Share Posted July 20, 2009 It's easier to code this than store it into a database. This is just pseudo code so it may need modifying to work but the basics are there. That and I'm mixing HTML with PHP but that's besides the point, it gets the basics out <?php $columns = 2; $total_records = 20; $column_split = ceil($total_records / $columns); echo '<table><tr>'; while ($row = mysql_fetch_array($sql)) { $count++; echo '<td>' . $row['tablerow'] . '</td>'; if ($count == $column_split) { echo '</tr><tr>'; $count = 0; } } echo '</tr></table>'; ?> Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted July 20, 2009 Author Share Posted July 20, 2009 I was able to get the effect that I wanted, by adding this to the loop: if($curCol != $row['column']){ echo '<div style="float:left;width:50%;">'."\n"; } include 'widget_name.php'; if($curCol != $row['column']){ echo '</div>; $curCol = $row['column']; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.