well, hope about this:

$count=0;
print "<table><tr>";
while (list($FirstName,$LastName)=mysql_fetch_row($result))
    {
    $count++;
    if ($count == 4)
        {
        $count=0;
        print "</tr>\n<tr>";
        }
    print "<td>$FirstName $LastName</td>\n";
    }
print "</tr></table>\n";

Or something like that...you get the idea??

You might also consider writint your prog so that it inputs all the info
into an array and then loops through it as you need to print (just for ease
of use).

Hope that help...it's at least a starting point.


Lewis


    "Brian Tully" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
I'm trying to figure out how I can format the results from a MySQL query so
that I can display several records per row, i.e., I'd like to be able to
format the results in a table with 3 columns, and as many rows as needed.
Please excuse my inability to be concise - my brain seems to be fried from a
long day.

I'm used to returning query results in a loop which prints out each record
in a row:

    while (list($FirstName, $LastName) = mysql_fetch_row($result)) {

        echo "
            <tr>
               <td>$FirstName $LastName</td>
            </tr>
        ";
    }


however that returns a page that looks like this:

Joe Cool
John Doe
Homer Simpson
Bob Vila
Dr. Suess
Captain Crunch



I'm hoping to display the results so that I can have several results per
line like so:

Joe Cool        John Doe        Homer Simpson
Bob Vila        Dr. Suess       Captain Crunch



in my na´ve thinking, I'm guessing that I'd need to count the query results
(mysql_num_rows) and divide them by 3.

so if I had 25 records and I wanted them listed 3 per line, I would divide
25/3 = 8.33 and round it up to the next number meaning I would have 9 rows,
the last row only having one record.

this is about as far as I get before I start getting a bad headache. ;)

I'm hoping someone might know of an article/tutorial on how to accomplish
this so I don't need to reinvent the wheel.

many thanks in advance,

brian









-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to