In order to change the color depending on weather or not the rs is empty you can use php to dynamically add in a style like this:
if($totalRows_<your rs> <= 0) print("style='background-color:red;'");
This would go in directly into the tag for the accordion tab.
As for the second thing you are asking about I'm not very clear on what you are looking to accomplish. It would be a good idea to explain how things should work from the perspective of the user that will be interacting with this. I think this should give me a better understanding of the situation and what may need to be done.