A
A
Alexander2015-10-05 12:19:50
MySQL
Alexander, 2015-10-05 12:19:50

Search from two columns from one value?

There are 3 columns in the database product , artikul, cats
In the input, the user can enter either an article that consists of an example: AL89T or the name of the product: Woody Woodpecker. cats 110 is a toy archive category.
I need, depending on what the user has entered into IPnut, to do a search in the database by products and articles and not take into account the archive of toys

SELECT * FROM toys_products WHERE product LIKE '%" . $_GET['prodect_like'] . "%' OR artikul LIKE '%" . $_GET['prodect_like'] . "%' AND cats NOT LIKE '%x110x%'"

Compiled such sql request but crookedly works. Finds even an archive of toys but not the name of the product or by article.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kovalsky, 2015-10-05
@kentuck1213

For the concatenation of SQL and Get parameters, hit yourself on the fingers.
You need to write a query using 2 variables. Something like

SELECT something from table1 
WHERE (@param1 IS NULL OR @param1 = col1) OR(@param2 IS NULL OR @param2 = col2)

And check the GET parameters themselves for validity and set them as values ​​to the specified variables

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question