Creating custom function in wordpress to return data from database

In your header.php

$images = getSliderImages();
    foreach ( $images as $img ) {
        echo '<img src="' .$img. '" />';
    }