My client got a excel file with the following structure
name | email
----------------------------
Name | email here
Name | email here
Name | email here
Name | email here
Name | email here
Name | email here
I would likes to make a MySQL database table according to this pattern and save the data into MySQL.
I am wonder how to do this.
Also there is an option needed
We have to check that if that corresponding user had a correct email address, ie of the form @ .
Can we check the data as a loop while importing ?
Also how to convert this data to MySQL ?
解决方案
Save this excel file as csv and run the following code with add your changings
$source = fopen('email.csv', 'r') or die("Problem open file");
while (($data = fgetcsv($source, 1000, ",")) !== FALSE)
{
$name = $data[0];
$email = $data[1];
mysql_query("INSERT INTO `table` (`name`,`email`) VALUES ('".$name."','".$email."') ");
}
fclose($source);