Re: multicolumn table

From: Date: Mon, 17 Dec 2001 15:16:33 +0000
Subject: Re: multicolumn table
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-77949@lists.php.net to get a copy of this message
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 "<tr><td>$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>\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; }
-- Jim Musil --------- Multimedia Programmer Nettmedia ------------- 212-629-0004 jim@nettmedia.com

« previous php.general (#77949) next »