LOL! I should have given more thought to how the solution I thought would work works because it really only works if the field has all the same length, except for the number. So it works for
Day 1
Day 2
Day 3
…
Day 10
But not for
Paris Day 1
Paris Day 2
London Day 1
London Day 2
…
London Day 10
In any case, I have found a fairly nice solution using FIND_IN_SET for the issue of arrays in custom SQL which might be handy for others going forward.
SELECT DISTINCT tbl_albums.album_id, tbl_albums.trip_id, tbl_albums.user_id, tbl_albums.album_name, tbl_albums.album_url, tbl_albums.cloudinary_version, tbl_albums.viewable_id
FROM tbl_albums
LEFT JOIN tbl_album_triptakers ON tbl_album_triptakers.album_id = tbl_albums.album_id LEFT JOIN view_album_tripbits ON view_album_tripbits.album_id = tbl_albums.album_id
WHERE tbl_albums.trip_id = :P1
AND IF(:P2, FIND_IN_SET(:P2, tbl_album_triptakers.triptaker_id), 1=1)
AND IF(:P3, FIND_IN_SET(:P3, view_album_tripbits.tripbit_id), 1=1)
AND IF(:P4, FIND_IN_SET(:P4, view_album_tripbits.category_id), 1=1)
AND IF(:P5, FIND_IN_SET(:P5, view_album_tripbits.country), 1=1)
AND IF(:P6, FIND_IN_SET(:P6, view_album_tripbits.city), 1=1)
ORDER BY LENGTH(tbl_albums.album_name), tbl_albums.album_name
I could probably write a custom formatter for that, but it would be nice if that was included in Wappler as it would save using .split(’,’) which I’ve always found a bit inelegant and not intuitive.
Back to the drawing board.
FYI - the 1=1 is there because MySQL requires an ELSE when using IF. I tried using CASE WHEN but couldn’t get it to work.