Page 1 of 1

Pls,GIve me an Idea

Posted: Sun Feb 10, 2008 11:46 pm
by Madhum
Hello,

i want to import & export contacts through my web address book and Outlook contacts.
i have the coding for imports & exports file.
my problem is, my database fields and outlook heading fields are defferent.so how can i import contacts?

import code

Code: Select all

if (isset($_POST['Import']))
{
$fileup=$_POST['myupload'];
echo $fileup;
   # first get a mysql connection as per the FAQ
include("connect.php");
  $fcontents = file ('./uu.csv'); 
  # expects the csv file to be in the same dir as this script
 
  for($i=0; $i<sizeof($fcontents); $i++) { 
      $line = trim($fcontents[$i]); 
      $arr = explode(",", $line); 
      #if your data is comma separated
      # instead of tab separated, 
      # change the '\t' above to ',' 
     
      $sql = "insert into ww(aa,bb) values ('". 
                  implode("','", $arr) ."')"; 
      mysql_query($sql);
      echo $sql ."<br>\n";
      echo $fcontents;
      if(mysql_error()) {
         echo mysql_error() ."<br>\n";
      } 
}}
 
 
[color=#8000FF]export code[/color]
 
 if (isset($_POST['Export']))
{
function cleancomm($comm) 
{ 
$comm1 = str_replace('?', ' ', $comm); 
$comm2 = str_replace(',', ' ', $comm1); 
return $comm2; 
} 
 
 
 
require 'connect.php'; 
//require 'opendb.php'; 
 
$fp = fopen('file.csv','wa'); 
$q = 'select * from address_details'; 
$query = mysql_query($q); 
while ($row = mysql_fetch_array($query)) { 
 
 
 
$nextline = $row[0] . ',' . $row[1] . ',' . $row[2] . $row[3] . ',' . $row[4] . ',' . $row[5] . ',' . $row[6] . ',' . $row[7] . ',' .$row[8] . ',' . $row[9] . ',' . $row[10] . ',' . $row[11] . ','. $row[12] .',' .$row[13]. ',' . $row[14] .',' . $row[15] . ',' . $row[16] . $row[17] . ',' . $row[18] . ',' . $row[19] . ',' . $row[20] . ',' . $row[21] . ',' . 
$row[22] . ',' . $row[23] . ',' . $row[24] . ',' . $row[25] . ','. $row[26] .',' .$row[27]. ',' . $row[28] .',' . $row[29] . ',' . $row[30] . $row[31] . ',' . $row[32] . ',' . $row[33] . ',' . $row[34] . ',' . $row[35] . ',' . 
$row[36] . ',' . $row[37] . ',' . $row[38] . ',' . $row[39] . ','. $row[40] .',' .$row[41]. ',' . $row[42] .',' . $row[43] . ',' . $row[44] . $row[45] . ',' . $row[46] . ',' . $row[47] . ',' . $row[48] . ',' . $row[49] . ',' . 
$row[50] . ',' . $row[51] . ',' . $row[52] . ',' . $row[53] . ','. $row[54] .',' .$row[55]. ',' . $row[56] .',' .$row[57]. ',' . $row[58] . "\r\n"; 
 
//this is my table fields
/*First,Last,Middle,Title,Job_Title,Company,Department,Office,Post_Office_Box,Address,City,State,ZipPostal_Code,Country,Phone,Mobile_Phone,Home2Phone,Pager_Phone,Home_Phone,Assistant_Phone,Business_Fax,Home_Fax,Other_Fax,Telex_Number,Display_Name,Email_Type,Email_Address,Home_Address ,Business_Address,Other_Address,Web_Page,Business_Address_Street,Business_Address_City,Business_Address_State,Business_Address_Postal_Code,Business_Address_Country,Business_Address_PO_Box,Address_Book,Email_2,Email_3,IM_Add1,IM_Add2,IM_Add3,Photo,Work_Phone_2,Assistant_Fax,H_Street,H_City,H_State,H_PO_Code,H_Country,P_Web_Page,Bday,Other_Phone,Notes,Username
//58*/
 
 
fwrite($fp,$nextline); 
} 
fclose($fp); 
}
any help greatly appriciate. :lol: