Frage

I am just displaying a news feed, and my problem is that I want to allow users to rate items. I read that I need to store them in a database If I want to rank it, but how??? Here's my code:

$data = file_get_contents('https://news.google.com.mx/news/feeds?hl=es&gl=us&q='.tennis.'&um=1&ie=UTF-8&output=rss');

$xml = new SimpleXMLElement($data);
$channel = array();
$channel['title']       = $xml->channel->title;

foreach ($xml->channel->item as $item)
{
    echo $article['pubDate'] = $item->pubDate;
    echo $article['description'] = (string) trim($item->description);
}

Can someone give ideas in how to do that? I think I should read and then insert into a database, and then I dont know. I need to design the table for the ranking. Are there any good tutorials for this?

War es hilfreich?

Lösung

From how you've described it I'd say there are 3 entities involved: the news stories, the ratings themselves, and the users who are doing the ratings.

  1. You'll need a table for the news stories. You will have to figure out how to identify each story (probably by its URL or somesuch). You'll also need a mechanism to insert new stories from the feed, into your database, while avoiding duplicates. (The reason being, it's not a good idea to store the entire URL of the news feed for rating in the system, as that will take up unnecessary space and slow down your queries.)

  2. A table for the users. You'll need some sort of authentication mechanism so that you know who's voting. You'll also need to write queries to verify that no one user can vote more than once on the same article.

  3. Finally the ratings table. This will reference the users and stories tables above using foreign key references, and will include a single numerical column for the rating.

I think the above is a good database design for your application ...

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top