My problem is, the array does not return the record id 31 to the record_id column. var_dump shows null for that. but 32 is returned.
Updated
SELECT *
FROM `expenses`
JOIN `expense_types` ON `expense_types`.`expense_type_id` = `expenses`.`expense_type_id`
LEFT JOIN `sub_payments` ON `expenses`.`record_id` = `sub_payments`.`record_id`
WHERE `expenses`.`record_id` LIKE '%%' ESCAPE '!'
OR `expenses`.`expense_date` LIKE '%%' ESCAPE '!'
OR `expense_types`.`type` LIKE '%%' ESCAPE '!'
OR `expenses`.`amount` LIKE '%%' ESCAPE '!'
OR `expenses`.`note` LIKE '%%' ESCAPE '!'
ORDER BY `expenses`.`record_id` DESC
when i executed the sql produced by above query in phpmyadmin directly, it works.
LIKE “%%” == IS NOT NULL ? (I’m guessing. It seems pretty uselss to me too.)
one of these things is not like the other~…
Your “it works” list shows NULL in the sub_id and id fields, indicating that there is no matching sub_payments entry with record_id 31.
Your query did exactly what you told it to do. It RIGHT JOIN’d a table in which one of the rows was missing, so it threw the data away.
Notice that your fields left-to-right for record_id are 31,NULL. If you stick both of those into an array, in-order, the NULL will be the thing left over.
This is a case of SELECT * biting you in the arse. Left join the table, and specify your select fields properly, and you’ll get the data you desire.