PDA

View Full Version : Iterating through categories and grouping listings in a...


wharris
06-07-2001, 11:43 AM
Our office uses an old FoxPro-based database as our primary membership database. Works fine for the accounting people but is horrible at exporting ascii-delimited files, and I need a clean ascii file to produce a print directory.

If I can work out one coding problem, the easiest solution will be to use PHP/MySQL to output the entire listing as an html doc and then copy-and-paste the output into Wordpad. I can cadge the coding and formatting for each individual member listing from my online directory. But the online directory searches on a single WHERE parameter (e.g., WHERE ID='$id' or 'WHERE bizname like '$keyword%'). Because this is for print, I need to print each category just once as a heading followed by the full listings of all members in that category ordered by business name like this . . .

AARDVARK DEALERS

Listing 1

Listing 2 etc.

ACCOUNTANTS

Listing 1

Listing 2 etc.

Since I have almost as many categories (400+) as members (1300), it will be very helpful if I can construct a loop to increment through all the categories. The ugly alternative would be to "ORDER BY category, bizname" and then manually add the category headings and delete the category line from each listing.

Thanks,
Wayne[nbsp]

Arthur
06-07-2001, 02:45 PM
If I understand your question correctly you could code something like;
-select everything in the directory into an array, sorted on category
-make an empty temp variable
-start looping through array
[nbsp][nbsp]-if temp variable <> category - print category, set temp variable = category
[nbsp][nbsp]-print listing

HTH,
Arthur

dank
06-08-2001, 01:24 AM
I would guess you could come up with the appropriate query with a &quot;GROUP BY Category&quot; clause.[nbsp][nbsp]You would probably end up with something along the lines of:

AARDVARK DEALERS|Listing 1
AARDVARK DEALERS|Listing 2 etc.
ACCOUNTANTS|Listing 1
ACCOUNTANTS|Listing 2 etc.

which could possibly be formatted the way you want with some find and replace's after the fact.[nbsp][nbsp]Just a thought (which, judging from my past 12 hours of database run-in's, isn't worth much).

Dan

wharris
06-14-2001, 11:15 PM
Belated thanks, Arthur and Dan. I wanted to follow Arthur's suggestions, but my skill sets were more compatible with Dan's.:)

Wayne