how can I return several query results per table row?
| From: | Brian Tully | Date: | Thu, 12 Sep 2002 05:33:06 +0000 |
| Subject: | how can I return several query results per table row? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116081@lists.php.net to get a copy of this message | ||
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