G
G
ganbatte2019-08-18 09:14:11
Laravel
ganbatte, 2019-08-18 09:14:11

How to implement multi-value search in php?

The search form has several lines, something like this
id, name, description, date
. For example, I want to search by these parameters. I am getting parameters. And sql looks like this.

select * from `table` where `id` = ? and `name` = ?  and `description` = ?  and `date` = ?

Here, but if there is an empty value in id, then how can you make sql look like this, in short, do not search with empty data.
select * from `table` where  `name` = ?  and `description` = ?  and `date` = ?

How is this done in general, what practices are used? I can simply write value="do not search" in the input,
and process everything with
if($id='не искать'){
select * from `table` where  `name` = ?  and `description` = ?  and `date` = ?
}
Is this the same way, or is there a better practice? I do this in Laravel, but I think the philosophy of the solution is the same in the code, or is there another solution in laravel?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2019-08-18
@ganbatte

The best practice is described in the documentation .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question