Sorry but I don't do PHP. You should post the source that the code produces (i.e. html and css).
If you want a caption under an image you simply need to float the image container and then place the caption under the image using a break tag or paragraph but keep both elements in the float.
The p tag is floated width a width and height that will accomodate the image and the text. If you don't set a height then when the floats wrap to the next line they will snag on the highest element in the line.
<p class="caption"><img src="images/photo-2.jpg" width="100" height="75" alt="" /><br />Caption</p>
You can float without widths but this means that the text can only be one work or two because it will not wrap at the image boundaries. The only way to make text wrap is to use a width on the float.
Here is a more advanced example that shows all the above and more but is a little complicated as it attempts to vertically center the images also.
The first example I posted gives the general idea in an easy format.
Hope it helps