[PHP] multicolumn table
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\ntd\nimg src=\img/letras/$curletra.gif\ width=\24\ height=\24\\n/td\n/tr\n; } $row .= tda 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]
Re: [PHP] multicolumn table
try to start the sql at a prompt and post the error which mysql returns Regards, Andrey Hristov - Original Message - From: Rodrigo Peres [EMAIL PROTECTED] To: PHP [EMAIL PROTECTED] Sent: Monday, December 17, 2001 4:04 PM Subject: [PHP] multicolumn table 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\ntd\nimg src=\img/letras/$curletra.gif\ width=\24\ height=\24\\n/td\n/tr\n; } $row .= tda 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] -- 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]
Re: [PHP] multicolumn table
Sorry list, I think, I was not clear enough. I don't have errors, what I could do with this code is output a table in alphabetical order ex: A a.. ab.. B b... bc... But what I really need and I couldn't make work is, my table output one name per row and a long one singlke column, and I need a table with 3 colmns and many rows as necessary to have all names. Thank's Rodrigo Peres on 12/17/01 12:10 PM, Andrey Hristov at [EMAIL PROTECTED] wrote: try to start the sql at a prompt and post the error which mysql returns Regards, Andrey Hristov - Original Message - From: Rodrigo Peres [EMAIL PROTECTED] To: PHP [EMAIL PROTECTED] Sent: Monday, December 17, 2001 4:04 PM Subject: [PHP] multicolumn table 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\ntd\nimg src=\img/letras/$curletra.gif\ width=\24\ height=\24\\n/td\n/tr\n; } $row .= tda 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] -- -- 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]
Re: [PHP] multicolumn table
Try something like this... $my_array = array( A=array(1,2,3),B=array(1,2,3),C=array(1,2,3)); $num_columns = 3; echo table; foreach($my_array as $key=$value) { echo trtd$key/td; for($i=1;$i=$num_columns;$i++) { echo td.$value[$i-1]./td; } echo /tr; } echo /table; Sorry list, I think, I was not clear enough. I don't have errors, what I could do with this code is output a table in alphabetical order ex: A a.. ab.. B b... bc... But what I really need and I couldn't make work is, my table output one name per row and a long one singlke column, and I need a table with 3 colmns and many rows as necessary to have all names. Thank's $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\ntd\nimg src=\img/letras/$curletra.gif\ width=\24\ height=\24\\n/td\n/tr\n; } $row .= tda href=\interna.php?cat=$resultado[Nome_Categoria]celebID=$resultado[CelebID ]\.$resultado['Nome_Artistico']./a/td\n; $ultletra = $curletra; } -- Jim Musil - Multimedia Programmer Nettmedia - 212-629-0004 [EMAIL PROTECTED] -- 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]
Re: [PHP] multicolumn table
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 whileceil($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\ntd\nimg src=\img/letras/$curletra.gif\ width=\24\ height=\24\\n/td\n/tr\n; } $row .= tda 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]