This is the code i came up with! But it is not 100%
<?php
 if (isset($Submit)) {
  // File is uploaded
      if ($uFile <> "") {
         if (!copy($uFile, $move_to_dir."/".$uFile_name)) {
            echo "No File Uploaded";
         }
         $curr = fopen($move_to_dir."/".$uFile_name, "r");
         while ($currar = fgetcsv($curr, 1000, ",")) {
            $CurrCode = $currar[0];
            $Currency = $currar[1];
            $From1 = $currar[2];
            $To1 = $currar[3];
            $ROEX = $currar[4];
            $sqlcurr="SELECT * FROM CurrencyNetwork WHERE CNCurr =
'$Currency'";
            $result = mysql_query($sqlcurr,$db_con);
            if (mysql_fetch_array($result)) {
               //Do Nothing
            } else {
            $sql="INSERT INTO CurrencyNetwork
(CNCode,CNCurr,CNAdBy,CNDtAd,CNROEX)
                  values ('$CurrCode', '$Currency', '$From1', '$To1',
'$ROEX')";
                  mysql_query($sql,$db_con);
            }

         }
         mysql_close($db_con);
      }
   }
 else
 {
  // No file uploaded, show the form
      echo "<div align='center'>";
  echo "Upload this file: <input name='uFile' type='file'>";
  echo "<input type='submit' name='Submit' value='Upload'>";
      echo "</div>";
 }
?>



"David Robley" <[EMAIL PROTECTED]> wrote in message
01091317241109.14360@www">news:01091317241109.14360@www...
> On Thu, 13 Sep 2001 16:52, you wrote:
> > There is a very good reason !
> > The csv file contains world currency's
> > The system is updated with the changed currency's only !
> > The Master field contains all country currency's , this makes it
> > difficult because if i drop the master table and upload the csv there
> > will only be a few currency's!
> >
> > Thanks
> > Coenraad Steenkamp
> >
> >
> > ----- Original Message -----
> > From: "David Robley" <[EMAIL PROTECTED]>
> > Newsgroups: php.general
> > To: "Coenraad Steenkamp" <[EMAIL PROTECTED]>;
> > <[EMAIL PROTECTED]>
> > Sent: Thursday, September 13, 2001 9:18 AM
> > Subject: Re: [PHP] Validate CSV file With Table in Database!!
> >
> > > On Thu, 13 Sep 2001 16:37, Coenraad Steenkamp wrote:
> > > > I need to compare a csv file to a table in the database but only
> > > > one field in the database with
> > > > one field in the CSV file! Comparing only one field will make it
> > > > much easier! When there is any change in the Database compared to
> > > > the CSV file , the database must then be updated or if there are no
> > > > such a field it must be added to the table!
> > > >
> > > > I am new in php Please help!
> > >
> > > That seems an awful lot of work, if you know that the csv is at least
> > > as up to date, if not more so, than the actual table. You might as
> > > well just drop the table and import the contents of the csv.
> > >
> > > Unless there's a good reason not to that you haven't mentioned?
>
> OK. So it sounds like you need to do something like:
>
> for each csv file line
>   select record where table_key = csvfield_key
>   if record found
>     if table_other_value != csv_other_value
>       update table with csv_value
>     end if
>   else (record not found)
>     insert new record
>   end if
> end for
>
> where the key might be perhaps the country name and the other value is
> the current currency.
>
> Am I on the right track? Does that help you any?
>
> --
> David Robley      Techno-JoaT, Web Maintainer, Mail List Admin, etc
> CENTRE FOR INJURY STUDIES      Flinders University, SOUTH AUSTRALIA
>
>    I am functioning within established parameters.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to