How to limit results

Discussion in 'PHP' started by Funk-woo10, Nov 2, 2007.

  1. #1
    Hi,

    On my data base a user an upload a set number of pics.

    At the mo I have a script that displays the last 5 users with pics uploaded.

    However I need to get it to only display 1 pic per username.

    How would i do this ? Script sample-


    <?
    $sql="select * from photos where approved='Y' order by upldate DESC LIMIT 5";
    $result = mysql_query($sql);
    $count=mysql_num_rows($result);
    
    
    						  $res=mysql_query($sql);
    						  while($obj=mysql_fetch_object($res))
    						  {
    					  		if($obj->url=="")
    							{
    								$img="<a target='_blank' href='../pics/$obj->filename'><img border=0 width=100 height=100 src='../pics/$obj->filename'></a>";
    							}
    							else
    							{
    								$img="<a target='_blank' href='$obj->url'><img  border=0 width=100 height=100 src='$obj->url'></a>";
    							}
    
    						  $id=$obj->photosid;
    						  $username=$obj->username;
    ?>
    
    
    
    
                                <td width="30%" align="center"><? print $img; ?></td>
                                <td width="20%"><a href="javascript:popupWindow('<? print $username; ?>');"><? print $username; ?></a></td>
    
    
    
    
    
    
                              <?
    						  }
    						  if($count!=0)
    						  {
    						  ?>
    
    
    
    
    
    
    
    						  <?
    						  }
    						  ?>
    PHP:

     
    Funk-woo10, Nov 2, 2007 IP
  2. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Change LIMIT 5 to LIMIT 1 in the second line from the top.
     
    tamen, Nov 2, 2007 IP
  3. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,108
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Not to worry I have sorted this....MODS CLOSE THREAD..
     
    Funk-woo10, Nov 2, 2007 IP