Many CMS sites having a facility to show the latest topics on site. I have created a general function for get the top 'n' posts. It is in PHP with MySql.
code:
< ?php
function select_top($table, $fields, $key, $nos)
{
//done by : thecoderin.gmail.com
//date: 28 feb 2009
$count_field = count($fields);
$query = "SELECT ";
for($i=0; $i<$count_field -1; $i++) +++$query = $query."`".$fields[$i]."`, ";
$query = $query."`".$fields[$count_field -1]."` ";
$query .= "FROM $table ORDER BY $key DESC LIMIT $nos";
// echo $query;
$result = mysql_query($query);
return $result;
}
?>
0 Response to "get top 'n' queries - php mysql"
Post a Comment