Group by week,month in mysql depending on php variable. If condition in group by
I have a table, prescription, which the fields
- prescription_id
- description
- patient_id
- pres_date
- title
I know how to group by month, week or day. My question is, i want this to be dynamic. I have an interface in the UI where the user will select a category, month, day or week. Which i store in a variable $category. Is there any way to use an if condition in group by to see which category the user has selected, and return the sql query in that format.
For example, if the user selects month, in my sql query, i want it to return, group by month(pres_date), if the user selects day, i want sql to return group by day(pres_date).
Total Views: 21 Today Views: 0
















