I'm trying to set up an app for users to put their individual photos into different albums, eg. friends, family, whatever. I would like one pic from that album to be displayed for each album along with the album name. I thought SELECT DISTINCT would do the trick for me but I'm not getting the desired results. It's still displaying all pictures with the appropriate album name even if they are duplicates. I'm sure I'm overlooking something simple as usual but my head is in a fog and I'm just not seeing it.
Here is where I'm at.
$sql="SELECT DISTINCT album, pic FROM user_profile_pics WHERE user_id='$uid' AND pic !='' ORDER BY def DESC";
$res=mysql_query($sql);
$i = 0;
$num_of_cols = 5;
echo "<table cellspacing=\"10\" cellpadding=\"10\"><tr>";
while($row = mysql_fetch_array($res)) {
echo ($i!= 0 && $i%$num_of_cols == 0)?'</tr><tr>':'';
echo "<td valign=\"bottom\" align=\"center\"><a href=\"../xpics/profiles/".$row['pic']."\"><img src=\"../xpics/profiles/small/".$row['pic']."\" border=\"none\"></a>";
echo '<br/>'.$row['album'].'';
echo"</td>";
$i++;
}
echo '</tr></table>';
Am I going about this the wrong way? It seemed like a no-brainer but isn't turning out that way.