I have a table that with name of key_words with one column call keywords. i want to retrieve keywords from database as random and show in Meta Keywords in header for better SEO .
i found a code here that was written by "smdrager" and tank from him.his code works good but written as array.
i changed it to connect database but does not works. it show all keywords in table and repeat keywords.
anybody can help me to achieve my goal? thanks all
function get_keywords(){
// $keywords=array('keyword1','keyword2','keyword3','keyword4','keyword5'); written by "smdrager"
include('config.php'); // Connect to Database
$query = mysql_query("SELECT keywords FROM key_words");
$all_entries = array();
while ($result = mysql_fetch_array($query)) {
$all_entries[] = $result[1];
$keywords= $result;}
if (count($keywords)<10)
$max=count($keywords);
else
$max=10;
$rand_keys = array_rand($keywords, $max);
foreach($rand_keys as $vals){
$keyword[]=$keywords[$vals];
}
echo implode(", ", $keyword);
}
?>