Consolidation Loans - Online Advertising - Power Rangers - Ringtone - Free Download

PDA

View Full Version : Mysql Query Problem


SpankedNutz
Oct 19th 2005, 10:06 am
Hi there,

This is what I want to do. I want to have one template php with the mysql query below:
The idea is that i can call one template file without physically having the files on the server:

I have this defined at the top of the page:

$cat = array('clothes','electronics');


And this is the query i want to run:
ps. This part from the query doesn't work Niche='$cat'
If i change the Niche='$cat' to Niche='clothes' then it works.

$sql = "SELECT Sitename_open, Sitename_closed, Message, Niche, IF (CHAR_LENGTH(Message)>100,RPAD(LEFT(Message,50),53,'.'),Message) AS Message FROM xxxxxxx where Niche='$cat' ORDER BY `Sitename_open` ASC";

I hope someone can help me

dct
Oct 19th 2005, 10:13 am
You would need the where clause to be:

where Niche = 'clothes' or Niche = 'electronics'

or

where Niche in ('clothes', 'electronics')


you could probably do

$sql = "SELECT Sitename_open, Sitename_closed, Message, Niche,
IF (CHAR_LENGTH(Message)>100,RPAD(LEFT(Message,50),53,'.'),Message) AS Message
FROM xxxxxxx
where Niche in ('" . implode("','", $cat) . "')
ORDER BY `Sitename_open` ASC";

SpankedNutz
Oct 19th 2005, 12:11 pm
That seems to work, but now i get all the categories in one single page.
I wanted this page to show only the items where Niche = Clothes when i open the virtual page :clothes.php

Any ideas how to do this?

Cheers