0

I have a query, that I have tested outside of PHP directly on SQL and still getting the same problem

The idea being that $currentArtist is sent through using the GET method, where this value matches the value in the event_artist columns the information is displayed.

SELECT 
            *
        FROM
            `".DBN."`.`events`
        WHERE
            `event_artist1` OR `event_artist2` OR `event_artist3` = '".$currentArtist."'

    ";

The problem I have is that it is completely ignoring the WHERE part of the query. It just returns the complete table results and not the results that match $currentArtist.

I have tested $currentArtist and it works fine. I'm at a loss as to how to get the complete statement to work.

I've tried surrounding the OR statements in brackets as in:

(`event_artist1` OR `event_artist2`...) = '".$currentArtist."'

This only returns a result if the $currentArtist is equal to "1" being the first person in the Artists table where their information is stored.

Any help would be greatly appreciated.

SamesJeabrook
  • 1,387
  • 5
  • 17
  • 27

3 Answers3

9
SELECT *
  FROM events e
 WHERE '$currentArtist' IN (e.event_artist1,e.event_artist2,e.event_artist3);
Strawberry
  • 33,750
  • 13
  • 40
  • 57
  • 1
    interesting, I've never tried putting columns in an `IN` clause, only constants... – Alnitak Mar 06 '14 at 13:24
  • Shouldn't it be `SELECT e.*` if you've assigned `e` for events? Or is that not required for a single table select? – Onimusha Mar 06 '14 at 13:24
  • 2
    It's not required, but it is good practice. Better practice is naming all required columns. – Strawberry Mar 06 '14 at 13:26
  • This was perfect, thanks for your help. I'm fairly new to MySql and PHP so I'm currently on the baby steps of the language, do you possibly know of a good tutorial to help me better understand the statement you have done above? – SamesJeabrook Mar 06 '14 at 13:31
0

try

SELECT * FROM `".DBN."`.`events` WHERE
            `event_artist1`= '".$currentArtist."' OR `event_artist2`= '".$currentArtist."' OR `event_artist3` = '".$currentArtist."'";
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
0
SELECT *
FROM `".DBN."`.`events`
WHERE `event_artist1` = '".$currentArtist."' 
OR `event_artist2` = '".$currentArtist."' 
OR `event_artist3` = '".$currentArtist."'
";

Hope this helps.

luv2code
  • 1,216
  • 6
  • 22
  • 42