Here is a script I use to create columns. I wrote this my first month phping, so it may be ugly. (Hence it may not be up to my new standards... :) Not to mention, this was designed for creating menu button which sounds different than what you do.
I use it as follows: display_columns( mysql query result, name of function that display's html row [, number of rows prefered]) · Since returned rows can vary, this function will try to force that number of rows. So you could end up with 15 million columns. · $max_columns determines the maximum number of columns and the script adjusts as needed. Default is three. · This will create the columns down then across. NOTE: I included my html function called 'regular_menu' Example use- /********************* $results = mysql_query(etc.); display_columns($results,"regular_menu"); **********************/ function display_columns($menu_query_result,$display_menu,$max_rows_allowed = 6){ /******************** Variables for Menus ********************/ global $page; $row_count = mysql_num_rows($menu_query_result); $max_rows_allowed = $max_rows_allowed; # Number of allowed rows per column $total_column_rows = $max_rows_allowed; # The default is 1 column X $max_rows_allowed /******************* Get $max_column and $max_rows and $width of entire Table *******************/ while($row_count > $total_column_rows){ $total_column_rows += $max_rows_allowed; } $max_columns = ($total_column_rows/$max_rows_allowed); ### limit the number of columns to 3 max- (Makes it easier to print) if($max_columns > 3){ $max_columns = 3; } ### Clean up columns while((((ceil($row_count/$max_columns))*$max_columns) - $row_count) > ceil($row_count/$max_columns)){ $max_columns--; } ### Define $max_rows now that $max_columns is defined $max_rows = ceil($row_count/$max_columns); $width = $max_columns * 200; /******************** Display this thing ********************/ $container_html = <<<EOQ <!-- Start container_html - Container of the columns. --> <TABLE cellspacing='0' border='0' align='center' width='$width'> <TR> EOQ ; print "$container_html"; /******************* Print Columns and Rows *******************/ ### Start Column ### for($column_counter = 0; $column_counter < $max_columns; $column_counter++){ $print_html = <<<EOQ <!-- New Column --> <TD valign="top" width="200"> <TABLE border="0" cellpadding="3"> EOQ ; print "$print_html"; ### Start and Stop Rows ### for($row_counter = 0; $row_counter < $max_rows; $row_counter++){ $ary = mysql_fetch_assoc($menu_query_result); if($ary){ $display_menu($ary); } ### End of Row Loop ### } $print_html = <<<EOQ <!-- Close Column --> </table> </TD> EOQ ; print "$print_html"; } $print_html = <<<EOQ <!-- Close Container --> </TR> </table> <br> EOQ ; print "$print_html"; } function regular_menu($ary){ global $page; extract($ary); $print_html = <<<EOQ <!-- Row --> <tr bgcolor="#003366"> <td width="200"> <div align="center"> <a href='http://$page?menu=$m_id' class='links'>$m_artical $m_name </a> </div> </td> </tr> EOQ ; print "$print_html"; } At 12:04 PM 12/17/2001 -0200, Rodrigo Peres wrote: >Hi list, > >I've tried for many times, but couldn't make a table with 3 columns and n >rows >This is my code, someone please, can help in make it outputs a 3 column >table?? > > >$sql = "SELECT >categorias.Nome_Categoria,celebridades.CelebID,celebridades.Nome_Artistico, >lcase(left(Nome_Artistico,1)) as letra FROM categorias LEFT JOIN >celebridades ON categorias.CategoriaID=celebridades.Categoria WHERE >CategoriaID='1' ORDER BY Nome_Artistico"; >$query = new Query($conexao); >$query->executa($sql); > >$ultletra = ''; >$row = ''; >while($resultado = $query->dados()) { > $curletra = $resultado['letra']; > if($curletra != $ultletra) { > $row .= "<tr>\n<td>\n<img src=\"img/letras/$curletra.gif\" >width=\"24\" height=\"24\">\n</td>\n</tr>\n"; > } > $row .= "<td><a >href=\"interna.php?cat=$resultado[Nome_Categoria]&celebID=$resultado[CelebID >]\">".$resultado['Nome_Artistico']."</a></td>\n"; > $ultletra = $curletra; > >} > >Thank's in advance > >Rodrigo Peres >-- > > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] >To contact the list administrators, e-mail: [EMAIL PROTECTED]