View Single Post
Old 01-16-2005, 09:56 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
well that is a lot of asking for 1 post, so i'll just show you how to get started for now. later, you can fire off more direct and specific questions as it starts to take shape.

first of all, php has a great function to read external files. file()

this function reads the file you give it into an array. so each line of the file is one element of the array.
PHP Code:
<?
$my_array 
file("http://www.domain.com/folder/file.csv");
?>
now, what you do next is going to be up to you. your pretty limited with arrays for filtering data management, so you might want to use a mysql database to temporarily store the csv information before you add the extra column.

after you read the file into an array, you might do something like this:
PHP Code:
<?
foreach($my_array as $line){
  
$row explode($line,",");

  
// maybe you can scan for duplicates here before you insert the line
  
$result mysql_query("select count(*) as count from table where field1='".$row[0]."'");
  
$num mysql_result($result,0,0);

  
// now only insert the row into the database table if it's not a duplicate
  
if($num==0){
    
$result mysql_query("insert into table (field1,field2,field3) values('".$row[0]."','".$row[1]."','".$row[2]."')");
  }
}
?>
without the data field, it's difficult to make a mock-up. you could either check the csv for updates, or just run the entire process all over again. that may be better since you have to read in the entire csv file anyway.

you would need to set this php script to run on cron or i think windows could run it as a 'scheduled task' (not sure on windows), .. then the php page that is being viewed is just viewing the latest database records.

my response is kind of all over the place, but your post is a little bit too. it's difficult to answer clearly, but i hope this helps a little.
__________________
Mike
sde is offline   Reply With Quote