moonwalker
moonwalker

Reputation: 485

How to show content for different or all categories?

I have a page called "categories.php". I use it to show different content for different categories.

Example:

mysite.com/categories.php?cat=dance (shows dancing content)
mysite.com/categories.php?cat=sing (show singing content)
Etc...

The database has two different tables:

Categories
categories_id
categories_title

Categories_content
cat_content_id
categories_id
categories_text
categories_image

So far so good. But now the problem I'm facing. Let's say I want to show a content on all the categories. Usually I'll have to add the same content for all the categories one by one. But I think there should be a way to add it only once and show it on all the pages.

I forgot to mention that I use a form with a dropdown menu where the categories are list for which I would like to add the content.

Any ideas how to do this? Do I have to use multiple SQL queries to achieve this?

Maybe I'm just making it hard for myself and there is an easy solution for this.

Thanks in advance. mw

Upvotes: 1

Views: 88

Answers (2)

user40330
user40330

Reputation:

If you create a new category called "all" or something, you can implement this in the query.

So instead of:

SELECT * FROM Categories JOIN [...] WHERE categories_title = '{$_GET['cat']}'

Use:

SELECT * FROM Categories JOIN [...] WHERE categories_title = '{$_GET['cat']}' OR categories_title = 'all'

Then on a category listing, filter out "all".

There are many ways of doing this, mine might not be the best but it's the best off the top of my head.

Upvotes: 1

Lazadon
Lazadon

Reputation: 193

You should just be able to use SQL without a where clause. It should return all id's regardless of categories_id.

Select cat_content_id from categories_content;

Upvotes: 1

Related Questions