I'm not instantly aware of a way to do exactly what you ask --- one could certainly use [man]mysql_num_rows/man to grab the total number of results from a query, then set a counter; that would be pretty common, I'd think.
The idea seems intriguing, and if there isn't, it might be nice to have; but, right now, it's Saturday night, kinda late, and I can't even begin to think of what problems might be inherent in trying to create such a function....