I could be wrong, but maybe try using
Using java Syntax Highlighting
if(current_images.first()) // I believe this will move cursor to first row
Parsed in 0.010 seconds, using GeSHi
before getting into your cursor iteration (=for) loop.
As a bonus, this should also take care
the case where there is no record returned as well
Hope it helps