[nycphp-talk] Newbie question: extract categories and display once

Jim Hendricks jim at
Thu Feb 13 08:12:46 EST 2003

A down and dirty way would be to define a variable which is initially blank
or null.

At the top of your loop which you use to iterate through the articles check
to see if the category associated with the article is the same as that
stored in the variable.  If it is different, pump out the category info and
set the variable to the category you just output.  If it is the same, skip
outputting the category info.

This assumes that your query which obtains the data brings it back in
category order.


----- Original Message -----
From: "QuicknEasyImage" <jim at>
To: "NYPHP Talk" <talk at>
Sent: Thursday, February 13, 2003 3:06 AM
Subject: [nycphp-talk] Newbie question: extract categories and display once

> Hi,
> I am creating a MSQL database of articles, all labeled by categories -
> marketing, copywriting, ecommerce and so on. I want to display the links
> these articles  on a web page, sorted by category. I only want to display
> the category name on the web page once - and underneath that, all the
> articles that fall into that category, then the next category name and all
> the articles under that that fall into that category, and so on.
> I can extract and display the links to the articles easy enough, but can't
> think how to make sure that the category name prints only once - at the
> of category list. Any ideas would be appreciated.
> Thanks,
> Jim
> --- Unsubscribe at ---

More information about the talk mailing list