Jump to content


Photo

datafeed


  • Please log in to reply
3 replies to this topic

#1 chery

chery
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts
  • Locationaustralia

Posted 25 May 2006 - 11:48 AM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]CSV Feed Live
You may retrieve the latest copy of the CSV feed at any time using the link below. This allows you to quickly save the feed from your browser or set up an automated import system to keep your database up-to-date automatically.[/quote]

How do I make an automated import sytem - one that will delete all entries and replace them with the new ones - and get it to update once per day perhaps?

I would appreciate any help as this one has me absolutely stumped.






chery
WWD GAMES - the BIGGEST little GAME site on the NET

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 25 May 2006 - 12:03 PM

You can parse a CSV file as easily as something like this:
<?php
$contents = file("http://www.thewebsite.com/file.csv");
foreach($contents as $line) {
    $line = explode(",",$line);
    //$line is now an array of all of the fields in the current line in the csv.
}
?>
That code should point you in the right direction, might be worth checking out file functions in the php manual too.

As for running once a day, you'd need to set up a cron job (if using *NIX) or an entry in Scheduler (if using Win).

#3 chery

chery
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts
  • Locationaustralia

Posted 25 May 2006 - 12:39 PM

[!--quoteo(post=376987:date=May 25 2006, 08:03 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ May 25 2006, 08:03 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You can parse a CSV file as easily as something like this:
<?php
$contents = file("http://www.thewebsite.com/file.csv");
foreach($contents as $line) {
    $line = explode(",",$line);
    //$line is now an array of all of the fields in the current line in the csv.
}
?>
That code should point you in the right direction, might be worth checking out file functions in the php manual too.

As for running once a day, you'd need to set up a cron job (if using *NIX) or an entry in Scheduler (if using Win).
[/quote]

Does this look right?
<?php
include("db.php");
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);

$contents = file("http://dc1datafeed.regnow.com/srv/rs.aspx?&afid=54516");
foreach($contents as $line) {
    $line = explode(",",$line);
    //$line is now an array of all of the fields in the current line in the csv.
}
?>

chery
WWD GAMES - the BIGGEST little GAME site on the NET

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 26 May 2006 - 12:41 PM

You might want to look up LOAD DATA INFILE = 'xxxx' command in the MySQL manual. It's much faster than parsing a CSV line by line
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users