[PHP-DB] Looping through a result

2004-04-20 Thread Rene Schoenmakers
Hi,

I want to make the following page,

Category 1
Item 1 of category 1 
Item 2 of category 1
Item 3 of category 1
Item 4 of category 1

Category 2
Item 1 of category 2
Item 2 of category 2
Item 3 of category 2

Category 3
Item 1 of category 3 
Item 2 of category 3
Item 3 of category 3
Item 4 of category 3
Item 4 of category 3,

using PHP and MySQL. Looping through a result is not the problem. But
how do I use a second query while looping through a result and do I have
to use more then 1 table in the database?
Can somebody point me in the right direction?

Tia,
 
René

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



Re: [PHP-DB] Looping through a result

2004-04-20 Thread Ignatius Reilly
Use only one query:

SELECT
category,
item,
...
ORDER BY category, item

Now fetch rows, and keep the latest categoryID in a flag variable:
- if fetched categoryID  flag, close table, create a new table, add header
row
- otherwise add content row to the current table
- update flag with the latest category ID

BTW you may want to use the great PEAR HTML_Table package to generate your
tables.

HTH
_
- Original Message -
From: Rene Schoenmakers [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, April 20, 2004 10:43 AM
Subject: [PHP-DB] Looping through a result


Hi,

I want to make the following page,

Category 1
Item 1 of category 1
Item 2 of category 1
Item 3 of category 1
Item 4 of category 1

Category 2
Item 1 of category 2
Item 2 of category 2
Item 3 of category 2

Category 3
Item 1 of category 3
Item 2 of category 3
Item 3 of category 3
Item 4 of category 3
Item 4 of category 3,

using PHP and MySQL. Looping through a result is not the problem. But
how do I use a second query while looping through a result and do I have
to use more then 1 table in the database?
Can somebody point me in the right direction?

Tia,

René

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

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



Re: [PHP-DB] Looping through a result

2004-04-20 Thread Mikael Grön
Rene,
This is a clarification of what I think Ignatius was talking about.
I did like this on www.deep-purple.com/tourdates:

Your database structure must look something like this for it to work:

ID  ITEMCATEGORY
1   1   1
2   2   1
3   3   1
4   4   1
5   1   2
6   2   2
7   3   2
8   1   3
9   2   3
10  3   3
11  4   3
Then you do like this with PHP:

?php
$SQL = select * from itemsAndCategories order by CATEGORY, ITEM;
$result = mysql_query($SQL);
$lastCategory = ;
while ($row = mysql_fetch_row($result)) {
if ($lastCategory != $row['CATEGORY']) {
$lastCategory = $row['CATEGORY'];
echo bCategory  . $row['CATEGORY'] . /bbr /\n;
}
echo Item  . $row['ITEM'] .  of category $lastCategorybr /\n;
}
?
This should generate the list you gave as an example..

Enjoy, Mike

On Apr 20, 2004, at 09:43, Rene Schoenmakers wrote:

Hi,

I want to make the following page,

Category 1
Item 1 of category 1
Item 2 of category 1
Item 3 of category 1
Item 4 of category 1
Category 2
Item 1 of category 2
Item 2 of category 2
Item 3 of category 2
Category 3
Item 1 of category 3
Item 2 of category 3
Item 3 of category 3
Item 4 of category 3
Item 4 of category 3,
using PHP and MySQL. Looping through a result is not the problem. But
how do I use a second query while looping through a result and do I 
have
to use more then 1 table in the database?
Can somebody point me in the right direction?

Tia,

René

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