| Author |
Message |
astrostart

Joined: 11 Feb 2007 Posts: 124 Location: The Netherlands |
|
Most populair news (views x rating) |
|
I want to make a page which shows the ten most populair news (like a list)
The rating should be as followed:
... views x ... Ajax rating = .... score
For instance. An article has been seen 500 times and has an Ajax rating of 5 then the score would be 2500!
I want to list the ten newsmessages with the highest score of the last 14 days. So when a newsarticle is 14 days old and its on the 1st place, it will fall out of the charts at the 15th day.
--- EXAMPLE ---
Place. Title newsarticle (score)
1. Senators asking for more money (9194)
2. Cutenews is great (8274)
3. FI-DD's hacks are greater (7052)
4. Blabla (4972)
5. .... (....)
6.
7.
8.
9.
10. The end (2593)
-------------------------------------
Is something like that possible? It would be so awesome!
_________________ My site: http://www.astrostart.nl | Thanks to everyone here who has helped me! |
|
| Sat Apr 07, 2007 10:37 am |
|
 |
Guest
|
|
|
Please login to hide the ads.
|
|
|
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2736 Location: Germany |
|
|
|
Open plugins/etc.php and add this at the end of the file above the last ?>:
 |  | function cn_ranking($days, $places){
global $sql;
foreach($sql->select(array('table' => 'news', 'where' => array("date > ".(time() - (86400 * $days))))) as $row){
$points = round(($row['views'] * ($row['rating']/$row['votes'])), 0);
$ranking[$points]['views'] = $row['views'];
$ranking[$points]['rating'] = $row['rating'];
$ranking[$points]['votes'] = $row['votes'];
$ranking[$points]['link'] = cute_get_link($row);
$ranking[$points]['title'] = $row['title'];
}
krsort($ranking);
$i = 1;
$output = '<table><tr><td>Place</td><td>Link</td></tr>';
foreach($ranking as $points => $value){
if($i <= $places){
$output .= '<tr><td>'.$i.'</td><td><a href="'.$value['link'].'">'.$value['title'].' ('.$points.')</a></td></tr>';
$i++;
}
}
$output .= '</table>';
return $output;
} |
Then add this where you want to show the list:
 |  | echo cn_ranking($days = 14, $places = 10); |
|
|
| Tue Apr 10, 2007 6:35 pm |
|
 |
Ramon
Joined: 12 Oct 2005 Posts: 462 Location: Hoogeveen, NL |
|
|
|
_O_
You should add this to the additional downloads section 
_________________
 |
|
| Wed Apr 11, 2007 12:45 am |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1843 Location: US |
|
|
|
Yeah that's really cool. So you're the PHP master, now the AJAX master, and also the math master?
_________________ www.scottdizzle.com uses cnr
last update: 07-22-08: 8:30 pm |
|
| Wed Apr 11, 2007 1:42 am |
|
 |
astrostart

Joined: 11 Feb 2007 Posts: 124 Location: The Netherlands |
|
|
|
I have no words... I'm speechless!
This is exactly what I had in mind! Wow! It's so great!
Thank you, FI-DD!!! 
_________________ My site: http://www.astrostart.nl | Thanks to everyone here who has helped me! |
|
| Wed Apr 11, 2007 1:28 pm |
|
 |
astrostart

Joined: 11 Feb 2007 Posts: 124 Location: The Netherlands |
|
|
| Wed Apr 11, 2007 2:14 pm |
|
 |
itzzmesur
Joined: 08 Feb 2007 Posts: 35
|
|
is there possiblity to restrict the categories in the utilit |
|
nice one ,
How to restrict the categories.....let's say i just want the top news from 3-4 categories from whole of 10 categories
|
|
| Tue May 08, 2007 9:04 am |
|
 |
alfred_rade
Joined: 01 Dec 2007 Posts: 24 Location: Buenos Aires |
|
FATAL ERROR!!! |
|
The plugin works perfect, until I recieve this message in my index page:
[b]Fatal error: Call to undefined function cn_ranking() in /home/diariola/public_html/index.php on line 471[/b]
LINE 471 SAYS:
<?PHP
cn_ranking($days = 14, $places = 10);
?>
I try everything that I could know. I'm stuck now!
Please, HELP! what could it be?
|
|
| Wed Feb 13, 2008 6:46 pm |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2736 Location: Germany |
|
|
|
Head.php must be included in index.php.
|
|
| Fri Feb 15, 2008 4:15 pm |
|
 |
acateoN
Joined: 12 Feb 2008 Posts: 47
|
|
|
|
Thanks for the top 10 script but I get an annoying error:
Top 10
Warning: Division by zero in /share/HDB_DATA/Qweb/xpl.se/plugins/etc.php on line 303
But the script works just fine, the top 10 news is shown beneath it.
Line 303 says:
$points = round(($row['views'] * ($row['rating']/$row['votes'])), 0);
|
|
| Wed Feb 20, 2008 3:29 pm |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1843 Location: US |
|
|
| Thu Feb 21, 2008 6:12 am |
|
 |
acateoN
Joined: 12 Feb 2008 Posts: 47
|
|
|
|
Unfortanetly it did not.
Same error still. : /
|
|
| Fri Feb 22, 2008 10:38 pm |
|
 |
alfred_rade
Joined: 01 Dec 2007 Posts: 24 Location: Buenos Aires |
|
|
|
head.php it was included in index.php and my rating not working
|
|
| Mon Feb 25, 2008 7:14 pm |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2736 Location: Germany |
|
Re: FATAL ERROR!!! |
|
 |  | The plugin works perfect, until I recieve this message in my index page: |
So it worked before? Then you must have changed something because a script doesn't stop on its own just like that.
And it's impossible to see the error message although you have correctly included head.php because head.php loads all plugins including etc.php which contains the cn_ranking() function. So somewhere you made a mistake. Don't know where...
|
|
| Wed Feb 27, 2008 8:11 pm |
|
 |
|