Display results from one table if has record in another

3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 28, 2010   (RSS)

By rjbathgate - July 27, 2010

Sorry, that subject is quite vague!

Two tables: News and Categories

Each News record has a Category assigned to it - i.e. linked list value.

On a page I want to display all categories, IF there is at least ONE news record assocaiated to that category.

At present, I do this by:

1) foreach category
2) list news records which have category num = this category
3) then, if there are no news records, continue to next category
4) else (ie if there are news records), then display category name

This works absolutely fine, but it has a large number of calls to the database, as for each category, it's calling the news table again and again.

So, I was wondering if there was a more efficient way to link the two tables without calling each one over and over again?

Or is this number of database calls not a problem to worry about?

Cheers!

Re: [Jason] Display results from one table if has record in another

By rjbathgate - July 28, 2010

Hey,

Thanks for the reply.

Your code does look alot simplier.

I'm returning all records and then applying a if none exist... so your count sounds better.

Thanks heaps,
Rob