$table = '';
$getfiles = mysql_query("SELECT * FROM tblfiles WHERE fkey = '$thiskey' ORDER BY fkey ASC ") or die (mysql_error());
while($row = mysql_fetch_assoc($getfiles))
{
$table .= '<p>'.$row['filename'].'</p>';
}
$table = preg_replace('/^<p>/', '<p class="first">', $table);
$table = preg_replace('/<p>([^<]*)</p>$/', '<p class="last">\1</p>', $table);
echo $table;