473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to import CSV data into MySQL with php?

26
Hi,


I need to update every column base on nric and year.

I use this code read and print the entire contents of a CSV file
Expand|Select|Wrap|Line Numbers
  1. $row = 1;
  2. if (($handle = fopen("student.csv", "r")) !== FALSE) {
  3.     while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
  4.         $num = count($data);
  5.         echo "<p> $num fields in line $row: <br /></p>\n";
  6.         $row++;
  7.         for ($c=0; $c < $num; $c++) {
  8.             echo $data[$c] . "<br />\n";
  9.         }
  10.     }
  11.     fclose($handle);
  12. }
  13.  
The above coding is correct or wrong.

i don't know, how to update every column base on nric and year in my database?

query is "INSERT INTO student (meta_aps) SELECT nric, year FROM student WHERE nric= 'this data from csv file'";--> This is correct

please give some idea.....
Mar 1 '11 #1
4 2218
johny10151981
1,059 1GB
What kind of CSV is this?

can you actually brows through the data?
Mar 1 '11 #2
apssiva
26
the data is in excel file, so i saveas into CSV
Mar 2 '11 #3
johny10151981
1,059 1GB
I think you should learn CSV structure a little more....
Mar 2 '11 #4
apssiva
26
Hi,

Below is my output, i want to Import CSV data into MYSQL database. pls only one help me.
how to update every column base on nric and year in my database?
Mar 3 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Matthias HALDIMANN | last post by:
When importing data into MS SQL Server 2000 from a MyODBC (v3.51) data source using Data Transformation Services, special characters like öäüéàè are not imported correctly. However, when the MyODBC...
2
by: Brett B | last post by:
I just installed mysql on linux. If I open a terminal, su to root, then type "mysql", I am able to connect to the server and run my queries. If I exit out of su so that I am my own id (baisley)...
0
by: James Moe | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I have an old-ish Sybase dbms (SQL Anywhere v5.x) that does not offer a DUMP command. The only way to extract data is to SELECT all of it,...
3
by: Sam Alexander | last post by:
Hi Everone, I'm writing a script to import data from an XML file, and this tutorial is really an awesome guide : http://www.kbalertz.com/Q316005/Import.Server.Component.aspx ... problem though...
2
by: Mike Collins | last post by:
I am importing a XML file and have not been having the best of luck in doing this, but I do have the following solution below. I will not be importing more than 2000 records at a time, but will be...
2
by: ScardyBob | last post by:
Hello, I am having trouble importing data from an Excel Worksheet. When I try to import the data, everything works except certain columns that contain dates, where it replaces the date with a...
3
by: mukeshsrivastav | last post by:
dear sir i want to move form excel to access. i have 5 excel file having same formats and fields.now i want to import all data in one access table. importing one file is easy .but importing and...
2
by: Alan M Dunsmuir | last post by:
A client has sent me a (Windows) Excel Spreadsheet (.xls) file containing a block of data he wants included as a table in a MySQL database in a (Linux-based) PHP/MySQL Web application I'm...
4
by: billelev | last post by:
I am importing data from a CSV file into an MS Database. The file containing the data has around 20 fields, and each field has a range of possible values. These values are known. I would like...
15
numberwhun
by: numberwhun | last post by:
Ok, let me preface this thread by saying that I cannot provide a real sample of the data that I am working with. The reason is, because it contains a lot of private, confidential information (for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.