-2

I tried to find in the internet how to use IF inside SQL command in PHP, but I could find a good tutorial.

So I want to make it

SELECT *,(neutral_kills*0.5 + rival_kills)/deaths AS totalkdr
FROM sc_players
ORDER BY totalkdr DESC
LIMIT 0,10

But I want to put IF (deaths == 0){deaths + 1}

How can I do it?

Adrian
  • 42,911
  • 6
  • 107
  • 99

1 Answers1

1

IF is used like a function:

SELECT *,(neutral_kills*0.5 + rival_kills)/IF(deaths = 0, 1, deaths) AS totalkdr
FROM sc_players
ORDER BY totalkdr DESC
LIMIT 0,10
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/bloodcra/public_html/pvp/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 94 Not working ): – Spaygot Minecraft May 07 '13 at 18:59
  • I fixed the unbalanced parentheses. If you're getting that error, it means you're not correctly checking for errors from `mysql_query()`. – Barmar May 07 '13 at 19:00
  • Actually, the error was that I wrote `==` instead of `=`. – Barmar May 07 '13 at 19:01
  • Yes, Its working now. Thanks, there is my rank: www.bloodcraft.com.br/pvp/rank – Spaygot Minecraft May 07 '13 at 19:03