Check out my code snippet below:
<div class="flexslider">
<ul class="slides">
<?php
$pre_ads_images=$conn->query("SELECT * FROM files WHERE pid=".$ad_out['id']);
while($ad_images=$pre_ads_images->fetch_assoc()){
echo'
<li data-thumb="'.$base_dir.'/uploads/post/'.$ad_images['uid'].'/'.$ad_images['name'].'">
<img src="'.$base_dir.'/uploads/post/'.$ad_images['uid'].'/'.$ad_images['name'].'" alt="'.$ad_out['title'].' For Sale In '.$city_y['name'].'"/>
</li>';
}
?>
</ul>
</div>
<script>$('.flexslider').flexslider({animation: "slide",controlNav: "thumbnails"});</script>