Hey
I am working on a tube site and I made a tags page showing all tags from all videos and their count..
The only problem is when I made my query I added "ORDER BY keywords ASC"
and so I got it sorted like: "amp, guitar, music" "guitar, jimi hendrix" "music, video, acoustic"
so once I added "preg_split" I have it like: amp, guitar, music, jimi hendrix, video, acoustic
so now I need to order it once more.
I tried using sort() and asort() but NO LUCK!
this is my code:
<?
$column=0;
$result = mysql_query("SELECT keywords FROM content ORDER BY keywords ASC")
or die(mysql_error());
$arr_keywords="";
while ($row = mysql_fetch_array($result)) {
$arr_keywords.= $row['keywords']." "; // make a big string from each post of the keywords
$arr_keywords = preg_replace('/\.[^.]+$/','',$arr_keywords);
$arr_keywords = strtolower($arr_keywords);
}
$tag = preg_split("/[\s,]+/", $arr_keywords); //make array of your keywords, splitting based on commas or white spaces (returns, space, tab, etc.)
foreach($tag as $keyword)
{
//loop through the list of all the words and build an array of them counting the number
//of times they occur so the final array will have a keyword list and a count.
if(!isset($list[$keyword])) $list[$keyword]=0; // initialize value
$list[$keyword]++; // increment count for that keyword
}
// remove words you don't care about
if(isset($list["and"])) unset($list["and"]);
if(isset($list["or"])) unset($list["or"]);
if(isset($list["the"])) unset($list["the"]); // etc....
foreach($list as $keyword=>$count){
$column=$column+1;
$rest = $column % 620;
$link='/search/'.$keyword.'/page1.html';
if ($rest == 1) { echo '<div style="width:220px; float:left; margin-left:15px; line-height:17px;">'; }
asort($keyword);
?>
<a href="<? echo $link; ?>" style="text-decoration:none;"><? echo $keyword. " (".$count.")<br>"; ?>
<? if ($rest == 0) { echo '</div>'; } }?>
Thanks in advance! 🙂