basing my code on yours:

    $i = 0;  $cols = 3;
    while (list($FirstName, $LastName) = mysql_fetch_row($result))
    {
        if ($i % $cols == 0)  echo "<tr>";
        echo "<td>$FirstName $LastName</td>";
        if ($i % $cols == $cols - 1)  echo "</tr>";
        $i++;
    }
    // clean up table...
    if ($i % $cols != $cols - 1)  echo "</tr>";


-----Original Message-----
From: Brian Tully [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 12, 2002 3:33 PM
To: PHP List
Subject: [PHP] how can I return several query results per table row?


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

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

Reply via email to