multiple values

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mrpaulfrank
Forum Commoner
Posts: 33
Joined: Sun Jun 23, 2002 3:39 am

multiple values

Post by mrpaulfrank »

im running a php script to search a mysql database. the table has a 'genre' column in it, and the php looks like this:

Code: Select all

if($genre = "comedy")
nothing big, but the problem im facing is this. some videos might pertain to a few different genres, and i want to somehow list all these genres in the 'genre' column and have the script search for the keyword in the value. after the if statement im running a loop that displays each result. does this all make sense?? ive tried inserting genres into the same 'genre' column separated by a space, comma...but then it wont find anything unless i search for exactly what the field says. anyone have any ideas on how to fix this one?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Once again, only because I'm feeling nice:
This

Code: Select all

if($genre = "comedy")
WON'T WORK - Every time it's run it will set $genre to 'comedy' no matter what $genre was before.

For the last time, to compare $genre to 'comedy' (or anything else for that matter)

Code: Select all

if ($genre == 'comedy')
Please note the double '=' instead of the single one.

Mac
mrpaulfrank
Forum Commoner
Posts: 33
Joined: Sun Jun 23, 2002 3:39 am

Post by mrpaulfrank »

ive changed this, its still working just fine. is there any way i can do something like this:

Code: Select all

$query_Recordset1 = "SELECT id, title, genre, format, image FROM test WHERE $genre=='genre', $genre=='genre2'";
i know this isnt right, but what i want to do here is set up a few (maybe three) genre columns for secondary genres that the video might relate to, in the table. and i want the script to find the results that match from all different genre columns? does this make sense?
DSM
Forum Contributor
Posts: 101
Joined: Thu May 02, 2002 11:51 am
Location: New Mexico, USA

Post by DSM »

Code: Select all

query_Recordset1 = "SELECT id, title, genre, format, image FROM test WHERE $genre = 'genre' OR $genre = 'genre2'";
mrpaulfrank
Forum Commoner
Posts: 33
Joined: Sun Jun 23, 2002 3:39 am

Post by mrpaulfrank »

Radical, i thought it would be something as easy as that. works like a charm, thanks a lot!
Post Reply