meganstar Posted June 22, 2010 Share Posted June 22, 2010 I have this code and currently the records are going down in rows. I would like the records to appear across next to one another and be able to adjust the number of columns if I'd like. Hope someone can help <table border="1" align="center"> <?php do { ?> <tr> <td><a href="questiondetails.php?recordID=<?php echo $row_sixities['ID']; ?>"> <?php echo $row_sixities['item']; ?> <br /> <?php echo $row_sixities['image_tb']; ?> </a></td> </tr> <?php } while ($row_sixities = mysql_fetch_assoc($sixities)); ?> </table> Link to comment https://forums.phpfreaks.com/topic/205592-mulitply-columns/ Share on other sites More sharing options...
wildteen88 Posted June 23, 2010 Share Posted June 23, 2010 See the following FAQ. Link to comment https://forums.phpfreaks.com/topic/205592-mulitply-columns/#findComment-1076153 Share on other sites More sharing options...
Psycho Posted June 23, 2010 Share Posted June 23, 2010 <?php //Var to adjust number of columns $max_columns = 6; function create_row($row_data) { if(count($row_data)<1) { return false; } $row_output = "<tr>\n"; foreach($row_data as $row) { $row_output .= "<td>"; $row_output .= "<a href=\"questiondetails.php?recordID={$row['ID']}\">{$row['item']}<br />\n"; $row_output .= "{$row['image_tb']}</a>\n"; $row_output .= "</td>\n"; } $row_output .= "<tr>\n"; return $row_output; } $current_col = 0; $row_data = array(); $table_output = ''; while($row_sixities = mysql_fetch_assoc($sixities)) { $current_col++; $row_data[] = $row_sixities; if($current_col%6==0) { $table_output .= create_row($row_data); $row_data = array(); } } $table_output .= create_row($row_data); ?> <table border="1" align="center"> <?php echo $table_output; ?> </table> Link to comment https://forums.phpfreaks.com/topic/205592-mulitply-columns/#findComment-1076212 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.