I would have done it a different way, but it would look something like that
this code has not been tested and is guaranteed to have bugs :) but it just
to get you started on a different approach.
====================================================
$ultletra = '';
$row = '<tr>';
while($resultado = $query->dados()) {
$curletra = $resultado['letra'];
if($counter++%3==0) {
$row .= "</tr><tr>\n";
}
$row .= sprintf("\n<td>\n<img src=\"img/letras/%s.gif\" width=\"24\"
height=\"24\">\n</td>",$curletra);
$row .= sprintf("<td><a
href=\"interna.php?cat=%s&celebID=%s\">%s</a></td>\n",urlencode($resultado[N
ome_Categoria]),urlecode($resultado[CelebI
D ]),$resultado['Nome_Artistico']) ;
}
while($counter++%3>0)
$row .= sprintf("<td> </td><td> </td>");
$row.="</tr>";
==================================================
Jerry Verhoef
-----Original Message-----
From: Miles Thompson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 27, 2001 4:20 PM
To: Rodrigo Peres; PHP
Subject: Re: [PHP] Create a table with more than 1 column
Rodrigo,
Nice looking page. I'm not going to try and fix your logic, because you've
approached it somewhat
differently than I would. Here's my logic or pseudocode ...
Set max_columns to 3
Set a letter variable
While I have results
While column_count is less than max_columns or letter is the same as
old_letter
Create a cell, fill it with data, echo it to screen
Increment the column counter
Set old_letter to this letter
Otherwise
Close the row, echo it
Start a new row, echo it
Reset column counter
Set a letter variable
That's roughly it. I've skipped putting in the cell for the letter graphic,
you may
want to do that in the Otherwise block. I've also skipped creation of the
initial row, which
would be done outside the while loop.
I know this can be improved upon to make it more robust, but let's hope it
gets you
to your goal.
Merry Christmas - Miles Thompson
On Thursday 27 December 2001 10:22 am, Rodrigo Peres wrote:
> Hi list,
>
> I am in a big trouble. My deadline is coming and I couldn't solve my
> problem yet! I have this script that outputs a table that can be seen at
> http://www.celebnet.com.br/abc.php
>
> $ultletra = '';
> $row = '';
> while($resultado = $query->dados()) {
> $curletra = $resultado['letra'];
> if($curletra != $ultletra) {
> if (!empty($row)) {
> $row .= "</tr>\n";
> }
> $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[CelebI
>D ]\">".$resultado['Nome_Artistico']."</a></td>\n";
> $ultletra = $curletra;
> }
> if (!empty($row)) {
> $row .= "<tr>\n";
> }
>
> SQL is:
>
> 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
>
> My problem is that I need to modify the script to output a 3 column table.
> I have tried everything but nothing works, and I've tried also all url
> about PHP that i could found. Please I'll appreciate any help.
>
> Thank's in advance and happy new year to all!!!
>
> Rodrigo Peres (Brazil)
--
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]
The information contained in this email is confidential and
may be legally privileged. It is intended solely for the
addressee. Access to this email by anyone else is
unauthorized. If you are not the intended recipient, any
form of disclosure, production, distribution or any action
taken or refrained from in reliance on it, is prohibited and
may be unlawful. Please notify the sender immediately.
The content of the email is not legally binding unless
confirmed by letter bearing two authorized signatures.
--
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]