PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Aug 15, 2020 2:53 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Fri Oct 13, 2017 10:49 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
We might be required to create a website whereby administrators can import a CSV into it.

I've done queries where you export a CSV, but not import.

Is it easy to do?
I know I would need to tie up the column headers in the CSV to the field headers in the database, but no idea how.

Any help would be appreciated.

Thanks.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Fri Oct 13, 2017 10:55 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
Take a look at .


Top
 Profile  
 
PostPosted: Fri Oct 13, 2017 11:00 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
Bloody hell that is a lot to read.
Surely it's more straight forward than that???

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Fri Oct 13, 2017 3:42 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
It's complicated because reading CSVs, processing data, and adding to a table is a complicated process.


Top
 Profile  
 
PostPosted: Fri Oct 13, 2017 3:46 pm 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
Often a practical solution, with some comments is better than [lots] [and] [lots] of tags on a screen that to some, is unreadable.

I had a Google for it and found a few results, with comments. Because the page you sent, sadly was just 'greek' to me. Sorry.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Fri Oct 13, 2017 3:56 pm 
Offline
Forum Regular
User avatar

Joined: Fri Sep 05, 2008 3:34 pm
Posts: 539
Location: Victoria, BC
I use something like:

Syntax: [ Download ] [ Hide ]
LOAD DATA LOCAL
        INFILE 'your file goes here.CSV'
INTO TABLE
        `your database goes here`
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 0 LINES;
 


everybody's favorite, SQL to the rescue

the code expects the CSV to be uploaded to the same box (VM) as the database server


Top
 Profile  
 
PostPosted: Fri Oct 13, 2017 4:16 pm 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4434
Location: United Kingdom
I Was reading about it and saw the script to look at the uploaded file.
Then the query. It seemed to ut each row into some sort of array,[0], [1]... and that went into insert script, lined up with the field names in the DB.

Into a Row.

A practical actual idea of the script is easier to learn from. That's what I mean.
Then comments to explain each part.
Rather than ... ENGINE + BRAKES + CALIPERS = Move then Stop.
An actual explanation of what the engine is doing, what the brakes are doing and so on.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Sat Oct 14, 2017 8:43 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
If you don't want to go with the method suggested above, you can do it all in PHP if you think that would be easier to understand. You reference a script in your last post, but didn't post it. Do you have anything written yet? What are you stuck on?

_________________


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 35 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group