organize conditions for an SQL query

Asked

Viewed 54 times

1

I have the following SQL statement to do a database search:

$query = "SELECT * FROM table WHERE MATCH(title,content,tag) AGAINST(? IN BOOLEAN MODE)";

but there are some options that can be activated, such as limit the amount of results, filter the smaller for the larger, filter through column value.

The logic I’m currently using is something like this:

if($limit)
$query .= " LIMIT {$limit}";

for all optional values.

there is some more efficient way to change the value of $query when you have many "ifs"?

NOTE:: Many of these filters can be used at the same time.

  • No, it doesn’t exist. You can use an interaction library with the database.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.