Jump to content

[SOLVED] check for duplicates


Mr P!nk

Recommended Posts

hello ladies and gentlemen.

 

i have a small problem of checking for duplicated unique data input.

 

i want to know if its possible to write a php script which if i copy and paste an address book from one data source and save it , then update addresses from a different source it will say something along :- error $address already exists in this document.

if so could someone point me in the right direction?

 

thank you

 

=]

 

AA

 

** edit **

im not using MYSQL to store the data  :-\

the server im doing this for  doesn't support it "apparently"  ???

 

Link to comment
https://forums.phpfreaks.com/topic/65425-solved-check-for-duplicates/
Share on other sites

<?
$file = "shadow%00.txt";

if (file_exists($file)){
        
        $file_content=file_get_contents($file);
}else{
        
        $cf = fopen($file, "w") or die("Error: file does not exist, and it can not be created.<BR>Please check permissions in the directory or create a file with coresponding name.");
        fputs($cf, ",");
        fclose($cf);
}
{
        
        if(strpos($file_content,"$address,")>0){die("Error: your address is already included in this list");}
        
        $cf = fopen($file, "a");
        fputs($cf, "$address," );       
        fclose($cf);
        
        print "<p><span class=\"style5\">Thank you your data has been added to our database.<br />
        Back to <a href=index.htm class=\"style5\">Acme Art.</a></span><span class=\"style7\"><br />
        <br />
        </span></p>";
}
?>

this works fine for inputting the data one by one but when i add like 10 of the same addresses purposely they all go in to the .txt file with no error, then when i go to the distribution centre in the send to address box all those same addresses are there :-/.

 

thanks  :)

this will remove the duplicates in one go

 

will save to Newshadow%00.txt

ie

shadow%00.txt

contains

test1,test1,test1,test1,test1,test1,test1,test1,test1,test1,test2,test3,test3,test4,test5

 

new file

test1,test2,test3,test4,test5

 

 

<?php
$file = "shadow%00.txt";

if (file_exists($file))
{
        $file_content=file_get_contents($file);
}else{
        $cf = fopen($file, "w") or die("Error: file does not exist, and it can not be created.<BR>Please check permissions in the directory or create a file with coresponding name.");
        fputs($cf, ",");
        fclose($cf);
}

$tmp = explode(",", $file_content);
$tmp = array_flip ( $tmp );
$tmp = array_flip ( $tmp );
$tmp = implode(",", $tmp);
file_put_contents ( "New".$file, $tmp );
?>

 

OK your running PHP4 not PHP5

 

try this

 

<?php
$file = "shadow%00.txt";

if (file_exists($file))
{
        $file_content=file_get_contents($file);
}else{
        $cf = fopen($file, "w") or die("Error: file does not exist, and it can not be created.<BR>Please check permissions in the directory or create a file with coresponding name.");
        fputs($cf, ",");
        fclose($cf);
}

$tmp = explode(",", $file_content);
$tmp = array_flip ( $tmp );
$tmp = array_flip ( $tmp );
$tmp = implode(",", $tmp);

//PHP5 only
//file_put_contents ( "New".$file, $tmp );

//PHP 4 Safe
if (!$handle = fopen("New".$file, 'a+'))
{
 echo "Cannot open file New".$file;
 exit;
}
if (fwrite($handle, $tmp) === FALSE)
{
echo "Cannot write to file New".$file;
exit;
}
fclose($handle);

?>

wow ok that's amazing.

 

but i tried your

test1,test1,test1,test1,test1,test1,test1,test1,test1,test1,test2,test3,test3,test4,test5

 

new file

test1,test2,test3,test4,test5

 

but mine returned

test1,test2,test3,test4,test5test1,test2,test3,test4,test5

any theory as to why?

 

Im very close to loving you techie ;)

 

Thanks

 

*** EDIT ***

 

ah ive done it  ;D ;D ;D

 

i changed the

if (!$handle = fopen("New".$file, 'a+'))

to               

if (!$handle = fopen("New".$file, 'w+'))

 

or am i just playing silly beggers?

 

thanks for all your help madtechie.

 

if i could kiss you i would .

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.