I have a query like
SELECT FirstColumn
WHERE SecondColumn = ?
AND ThirdColumn = ?
There may be situation that for one ? value is provided, but for another ? there is no value. Like
[0] => 123
[1] =>
So query may be SELECT FirstColumn WHERE SecondColumn = 123 AND ThirdColumn = ''
When experimented, see that for such query mysql returns nothing (no array).
But necessary is to return array with empty value or NULL or zero. Like
[0] => Array
(
[FirstColumn] => 0
)
So trying to find solution.
One solution may be to create row in mysql where FirstColumn, SecondColumn and ThirdColumn is 0. And with php modify data for ? so if empty variable, then data for ? is 0. Then use the same mysql query. Seems this is not very good solution.
Other solution would be query something like this
SELECT FirstColumn
WHERE SecondColumn = IFNULL(?,0)
AND ThirdColumn = IFNULL(?,0)
Created mysql row with 0, executed query. All works, but does not return array element where SecondColumn or ThirdColumn is 0. Something wrong with my query or may be IFNULL can not be used in such a way. Please, advice what need to correct? Or may be better solution?
Tried with
SELECT FirstColumn
WHERE SecondColumn = 0
AND ThirdColumn = 0`
and get array with 0 value. Possibly IFNULL used incorrectly...
FROMin there somewhere, so how about showing us your entire code, not just remnants.SELECT CurrencyAbbreviation, TRIM(TRAILING '0' FROM CurrencyRate/Units) AS FinalCurrencyRate FROM 2013Currencies WHERE (DateOfCurrencyRate = IFNULL(?,0) AND CurrencyAbbreviation = IFNULL(?,0)) OR (DateOfCurrencyRate = IFNULL(?,0) AND CurrencyAbbreviation = IFNULL(?,0))