<?php
function smarty_modifier_get_list_cover($id)
{
global $mysqli;
$sql = "SELECT lists_media.list_id,lists_media.media_id,media.id,media.thumbnail FROM lists_media JOIN media ON lists_media.media_id=media.id WHERE lists_media.list_id='$id' ORDER BY rand() LIMIT 1";
$query = $mysqli->query($sql);
$check = $query->num_rows;
if ($check == 0) {
return 'upload/no-list-cover.jpg';	
} else {
$row = $query->fetch_assoc();
return 'upload/media/'.$row['thumbnail'];
}
}
?>