I am working on an issue management system, developed in PHP/MySQL. It requires search functionality, where the user will mention the search parameters and based on these parameters the system will return the result set.
Bunu çözmek için ben bir işlevi yazmak çalışıyorum ve tüm kullanıcı seçilen parametreler argüman olarak geçirilir. Argümanlara dayalı dinamik sorgu üretecektir. Zaman zaman (kullanıcı tarafından yapılan tercihlere göre) bu argümanların bir veya daha fazla boş olabilir.
A Sample Query:
select * from
tickets
inner join ticket_assigned_to
on tickets.id=ticket_assigned_to.ticket_id
where
tickets.project_id= in ('')
and tickets.status in ('')
and ticket_assigned_to.user_id in ('')
and tickets.reporter_user_id=''
and tickets.operator_user_id in ('')
and tickets.due_date between '' and ''
and tickets.ts_created between '' and '';
Ben de argümanlar ORed'dir veya sorguda ANDed olabilir davalarını gerekir.
Örneğin:
select *
from
tickets
inner join ticket_assigned_to
on tickets.id=ticket_assigned_to.ticket_id
where
tickets.project_id= in ('')
and tickets.status in ('')
or tickets.due_date = ''
or tickets.ts_created between '' and '';
I am also planning to use the same function at other places in the project also. Like to display all the tickets of a user or all tickets created between given dates and so on...
How to handle this situation?
Should I go with a single function which handles all this or numerous small functions?
Need guidance here.