Answer the question
In order to leave comments, you need to log in
How to write a SQL SELECT PDO PHP query to get data for two rows?
I'm trying to implement getting data from the database in two lines
SELECT * FROM `table_products` WHERE `product_type` = :product_type AND `product_group` = :product_group
Answer the question
In order to leave comments, you need to log in
I'm trying to implement getting data from the database in two linesNot by rows, but by columns, they usually say "by fields". The most obvious and simple solution is to check for the presence of a variable and accordingly add the required field "manually" by concatenating query strings.
Sadly, as I understand it, SQL is poor here, and you have to fence a cloud of lines of php code, but I was hoping!
since it is not said what kind of logic in the request should be with zero values, I chose the option in the example - and zeros in the database too.
select .. from ... where ... and (:product_group is null and `product_group` is null) or (`product_group` = :product_group)
set @product_group=:product_group
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question