Jump to content

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....

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.