Display the 1st image file uploaded to a folder using php
<p>ok so I have this code working that it pulls out all the image files in a folder. There is a folder for each different product that has many images in them I want to pull out the 1st image that was uploaded to each folder and display them all on the same page.  At the minute I am displaying all the images from each folder.  </p>

<p>Below is the foreach I am using:</p>

<pre><code>  $albums = get_articles($albums);

if (count($albums)==0) {
echo "Sorry, no portfolios.";

} else {

foreach($albums as $article) {  


echo '&lt;img src="uploads/', $article['album_id'], '/', $article['image_id'],    '.', 
$article['ext'], '" title="Uploaded ', date('D M Y / h:i', $article['timestamp']), 
'"width="450" height="328"/&gt;';    


}

}
</code></pre>

<p>Below is the function I am using:</p>

<pre><code>function get_articles($albums) {

$albums = array();

$per_page = 9;     

$pages_query = mysql_query("SELECT COUNT(`album_id`) FROM `albums`") or
die(mysql_error());


     $pages = ceil(mysql_result($pages_query, 0) / $per_page);

     $page = (isset($_GET["page"])) ? (int)$_GET["page"] : 1;
       $start = ($page - 1) * $per_page;



 $query = mysql_query("SELECT * FROM `albums`,`images`  WHERE  
 albums.album_id=images.album_id AND code='css' LIMIT $start, $per_page ");



 while ($row = mysql_fetch_assoc($query)) {
    $albums[] = array(
    'album_id' =&gt; $row['album_id'],
    'name' =&gt; $row['name'],
    'image_id' =&gt; $row['image_id'],
    'ext' =&gt; $row['ext'],
    'timestamp' =&gt; $row['timestamp'],
    'description' =&gt; $row['description'],
     'type' =&gt; $row['type'],
     'code' =&gt; $row['code']




    );

 }
  if ($pages &gt;= 1 &amp;&amp; $page &lt;= $pages) {
        for ($x=1; $x&lt;=$pages; $x++) { 
            //echo $x, ' '; 

            echo ($x == $page) ? '&lt;span id="page"&gt;&lt;span class="page"&gt;&lt;a href="? 
page='.$x.'"&gt;'.$x.'&lt;/a&gt;&lt;/span&gt; ' : '&lt;span class="page"&gt;&lt;a href="?page='.$x.'"&gt;'.$x.'&lt;/a&gt;
 &lt;/span&gt;&lt;/span&gt; ';
        }

}
return $albums;

}
</code></pre>
