Cao,
ja sam skoro radio nešto slično sa .CSV fajlom, nisam siguran ali mislim da Eksel može da eksportuje i takav fajl.
Ako moraš da koristiš .TXT fajl onda samo zameniš funkciju 'fgetcsv' sa odgovarajućom za .TXT fajl valjda 'fgets'.
Moj script briše red ako je email adresa jednaka, ti promeni sql upit da setuje polje 'provera' na 0 ako je link jednak.
$link = $data[0];
Nešto tipa : UPDATE imeTabele SET provera = 0 WHERE link =$link
To je odprilike
Code:
<?php
/**
* Script for deleting records from the database which contain bounced emails
* The .csv file contains the bounced emails
**/
$start_time = time();
//Your settings to change here:
//*****************************
//Database related settings
//-------------------------------
$db_server = "your_database_server"; //database server name
$db_username = "your_database_username";
$db_password = "your_database_password";
$db_database_name = "your_database_name"; //database name
$db_database_table = "your_table_name"; //table name
$db_database_fieldname = "your_field_name"; //column name that contains the client email
//--------------------------------
//Your .csv file name setting
//---------------------------
$filename = "dpreport.csv";
//---------------------------
//*****************************
//The script itself:
//Connecting to the database
$db_connection = mysql_connect($db_server,$db_username,$db_password)
or die("Unable to connect to the database!");
//Linking to the specified database name
$db = mysql_select_db($db_database_name,$db_connection)
or die("Unable to link with the specified database name!");
//Open the file for reading
$handle = fopen($filename, "r");
//Number of deleted rows
$rows = 0;
//For each line of the .csv file drop the record(s) if the email match
//The longest possible email in the database is 50 characters
while (($data = fgetcsv($handle, 50, ",")) !== FALSE)
{
//The first column in the .csv file (= the email)
$email = $data[0];
//If the line in the .csv file is blank we jump to the next iteration
if ($email == NULL)
{
continue;
}
$result = mysql_query("DELETE from $db_database_table WHERE $db_database_fieldname = '$email' ");
//Increment the number of rows deleted
if ($result)
{
$rows += mysql_affected_rows();
}
else
{
die($rows . ' rows already deleted but stopped by error. Invalid query: ' . mysql_error());
}
}
$end_time = time();
//Duration of the execution in seconds
$duration = $end_time - $start_time;
//Print that the script has finished and how many rows were deleted
echo "The script has terminated the execution in ". $duration . " seconds." . "<br />";
echo "Number of records deleted: " . $rows ;
//Close the file from reading
fclose($handle);
//Close the connection to the database
mysql_close($db_connection);
?>
[izmenio Nemanja: Kôd stavljajte u CODE tagove!]
[Ovu poruku je menjao Nemanja Avramović dana 07.08.2009. u 19:44 GMT+1]