Jump to content

Using multiple CASE conditions.... PHP SQL


lakeshoretech

Recommended Posts

Can someone take a look at this?  I'm trying to add a 2nd case condition to my where statement.    This works perfectly UNTIL I add the second CASE, then I get no output whatsoever.  Variables are from a user form.  When I hard code these, it pulls correctly (one at a time).  Am I missing something obvious here?

 

WHERE....
uba_players.player_status <> '7 - Quit' AND
(CASE $player_age
WHEN 999 THEN uba_players.player_age like '%' AND
ELSE uba_players.player_age = $player_age AND
END)
(CASE '999'
WHEN 999 THEN uba_players.player_status like '%'
ELSE uba_players.player_age = $player_status
END)
ORDER BY.....

Link to comment
https://forums.phpfreaks.com/topic/218356-using-multiple-case-conditions-php-sql/
Share on other sites

To explain the reason for the CASE statement (I would use something else if recommended)

 

User has two choices before they pull the search.

 

1) AGE (player_age) - ALL ages = 999, or a specific age selection

 

AND

 

2) STATUS (player_status) - ALL status = 999, or a specific status selection

(on the 2nd case, I'm just trying to get it to work at all with a hard coded 999)

....
(CASE $player_age
WHEN 999 THEN uba_players.player_age like '%' AND
ELSE uba_players.player_age = $player_age AND
END)
(CASE '999'
WHEN 999 THEN uba_players.player_status like '%'
ELSE uba_players.player_age = $player_status
END)
ORDER BY....

 

2 "AND" in the first CASE are wrong... try

....
   (CASE $player_age
WHEN 999 THEN uba_players.player_age like '%'
ELSE uba_players.player_age = $player_age
   END)
AND
   (CASE '999'
WHEN 999 THEN uba_players.player_status like '%'
ELSE uba_players.player_age = $player_status
   END)
ORDER BY....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.