$cerereSQL = "SELECT * FROM `gallerycat` , `gallery` WHERE gallery.cat = gallerycat.id ORDER BY `catname`";
$rezultat = mysql_query($cerereSQL);
while($rand = mysql_fetch_assoc($rezultat))
{
?>
$array[]=$rand['catname'];
while (list (,$value) = each ($array))
{
echo $value."
";
}
} ?>