Have had time, but couldn't really find a solution.My best suggestion is to modify the query so that you check if a department is there or not - and then it shall give you all the tickets when ticket.dept is not empty.$qwhere .= ' AND ticket.dept_id IS NOT NULL';Not sure how or if $qstr needs to be changed too, but with the above where clause all tickets which have a value under ticket.dept_id shall be displayed (at least I hope so - haven't tried).Another possibility would be to make a foreach loop and create an array or so with the tickets for each department, sort the array then by date, ticket number, or something else and then just show the array with all the tickets.