D
D
dk-web2015-09-22 11:03:09
PHP
dk-web, 2015-09-22 11:03:09

How to simplify the processing of a very large form?

Was digging through my archives... and found one big statistical form. Search for objects by a huge cloud of parameters.
Roughly speaking, the query is as follows: SELECT * FROM ... as A INNER
JOIN ... as B .... and so 6 tables WHERE 1=1 and then dozens AND we get ... AND pokazatel IN ($checkbox_values) there is a field (select > < =) and a text input, then we get AND pokazatel $select_value.$input_value in general, the bottom line is that each indicator then had to be written with pens ... it turned out about 3000 thousand lines) and now change something ... it's easier to delete everything. Have a recipe? where to read and see?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evgeny Akhmetov, 2015-09-22
@asperin2

I would create an array of options, something like

$data = [1 => ['param' => 'name', 'cond' =>'=', 'value' => $name],
              2 => ['param' => 'age', 'cond' =>'>', 'value' => $age],
              .......
]

Then, through foreach, add to the request ... it's much more convenient to control the parameters like this.

V
V Sh., 2015-09-22
@JuniorNoobie

For ordinary users, this filter form can be simplified. For advanced users, provide the ability to write filters in a pseudo-language using "AND/OR", "CONTAINS", etc. Then just parse the string, parse it and make a normal query.
Or you collect all the information from the form in xml and send it to the database, where you parse it into components. When changing the form (adding new columns), it will only be necessary to change the parsing procedure in the database. And if you write a universal one, then you don’t have to do this either.

D
DVamp1r3, 2015-09-22
@DVamp1r3

through foreach and reflection, go through all the parameters, depending on the type, you generate pieces of the request. but you also do form element names with a data type prefix to expect what values ​​should be.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question