Where are you specifying if the image should align left or align right? Does it have a separate column in your table?
If so, you could easily add a CSS class that would use the attribute assigned to the image to float the image left or right as needed.
for example
echo '<img src="' . $row['img_src'] . " style="float:' . $row['img_float'] . ';" />';
or,
echo '<img src="' . $row['img_src'] . " class="' . $row['img_class'] . '" />';
OR,
echo '<img src="' . $row['img_src'] . " algin="' . $row['img_alignment] . '" />';
But I need to know how you are and what you are storing in your table...
(Basically, this is stating what Brad suggested in another way that you might understand better perhaps... ?)