Forum Moderators: coopster

Message Too Old, No Replies

count occurrence for huge number of words

         

hanyaz

11:07 am on Apr 16, 2009 (gmt 0)

10+ Year Member



Hello,
I got a table containg a list of names (around 800 names) and a table containing more than 1000 articles, i want to know if it is possible with mysql+php to make a list of say 20 most cited names in my article table.
I will have to count the occurence of each of the 800 names and then sort them. I just wonder if it is feasible and if it will not crash my server as the articles number will be increasing.
Can somebody advice on this ?
Thanks
hanyaz

hanyaz

2:12 pm on Apr 16, 2009 (gmt 0)

10+ Year Member



Here is the code that allows me to do so and store the results in a table...it does the job but i got 2 issues :
1- it displays an error at the top of the page :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
2-it is a bit slow, i think perhaps it is because of the $total query, how can i make it faster ?
Please help me.

function get_rows ($key)
{

$total = mysql_query("SELECT COUNT(*) FROM article WHERE title REGEXP '[[:<:]]($key)[[:>:]]'");

$total = mysql_fetch_array($total);
return $total[0];

}

$sql= mysql_query ("select * from author ");

while ($results= mysql_fetch_array ($sql))
{

$id= $results['id'];
$number=get_rows ($key);

mysql_query("UPDATE author SET occurence='$number' WHERE (id='$id')");

}