Tonny Feriandi Tonny Feriandi - 3 months ago 10
Java Question

how to disable "WHERE" condition on php

I have

WHERE
clause in my PHP. I need that condition, but sometimes I don't need it, here's my code:

(SELECT * FROM jasa WHERE kota = '$kota' order by id desc LIMIT :hal,7)


I need to know how to disable that clause. Sometimes I need a special condition from my data but sometimes I need to take all the data, or is there any command to take all data with
WHERE
clause?

My best solution is use if command on my android apps, but it will take a long time and code.

Answer

Take the "where condition" out from the query and make the condition separately and add with the query .

if(condition to use where condition)
    $where = "WHERE kota = '$kota'";
else
    $where = "";
$query = "SELECT * FROM jasa ".$where." order by id desc LIMIT :hal,7";
Comments