Discuss Function Most repeated words in the PHP Development forum on Dev Shed. Function Most repeated words PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 12,680
Time spent in forums: 5 Months 1 Week 4 Days 1 h 55 m 14 sec
Reputation Power: 8969
Change for why: it's bad data structure and is hard to use. As you're finding out.
Change for what: rather than store everything as a comma-separated list, store everything in a table with one row per page per keyword.
Code:
page id | keyword
--------+--------
1 | page
1 | google
1 | facebook
1 | smile
1 | more
1 | post
1 | thread
1 | msn
So the question stands: can you change the database structure?
Posts: 6
Time spent in forums: 1 h 11 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
Change for why: it's bad data structure and is hard to use. As you're finding out.
Change for what: rather than store everything as a comma-separated list, store everything in a table with one row per page per keyword.
So the question stands: can you change the database structure?
okay , requinix
maybe u are right ... but i can't change for that actually
listen i use that Function for same database and same field
PHP Code:
function get_keys($text,$limit=10){
$separaotr = " "; // the separator between the words
$text = str_replace(array('&','^',',',';','<','>','_','$','%','#','@','+','=','-','/','*',')','(','0',']','[','{','}'),$separaotr,$text) ;
$text = trim(strtolower($text));
$text = implode($separaotr, array_slice(explode($separaotr ,$text), 0, $limit));
$tags = array_unique(explode($separaotr,$text));
$num = count($tags) ; // number of tags you want
for ($z=0;$z<=$num;$z++){
$words .= '<a title="'.$tags[$z].'" href="search.php?q='.$tags[$z].'">'.$tags[$z].'</a> ';
if($z < $num-1){
$words .= ' ';
}
}
return $words;
}
this function show The words without repetition and without Signs , worked fine
but i want only Most 10 repeated words
can u Modify for what I want ...
the query :
PHP Code:
$tags = @mysql_query("SELECT page_keywords FROM pages ") or die(mysql_error());
Posts: 12,680
Time spent in forums: 5 Months 1 Week 4 Days 1 h 55 m 14 sec
Reputation Power: 8969
If you really can't do anything about it then the solution is (looks like) what you have: get all the keywords from all the pages and tally them in PHP.
Posts: 6
Time spent in forums: 1 h 11 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
If you really can't do anything about it then the solution is (looks like) what you have: get all the keywords from all the pages and tally them in PHP.
i do that already , i get all keywords from all pages
by this
PHP Code:
$tags = @mysql_query("SELECT page_keywords FROM pages ") or die(mysql_error());
Posts: 12,680
Time spent in forums: 5 Months 1 Week 4 Days 1 h 55 m 14 sec
Reputation Power: 8969
Don't yell. You won't win.
The function will be the one you write. Because we're not going to write it for you.
You already have a list of the keywords. If you need something to count the keywords then
PHP Code:
$count = array();
// for each $keyword in the list {
if (isset($count[$keyword])) $count[$keyword] = 0;
$count[$keyword]++;
// }
Posts: 6
Time spent in forums: 1 h 11 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
Don't yell. You won't win.
The function will be the one you write. Because we're not going to write it for you.
You already have a list of the keywords. If you need something to count the keywords then
PHP Code:
$count = array();
// for each $keyword in the list {
if (isset($count[$keyword])) $count[$keyword] = 0;
$count[$keyword]++;
// }
okay .. i understand
I did not ask you to write new function
I thought that there already function Available for this job
and i don't yell , sorry but u want me modification the database and i don't want do this ...
thnx ... requinix