I have some code to import data from a csv file into a mysql table like below. It works perfectly. What I need to do, though, is to get it to import all of the 154 fields except the first 5. Actually, the 1st field (before the comma) is a blank field which is the auto-incrementing id field. Then it's the next 4 that are the problem. In the mysql table, these fields must not have data entered by the import, but all other fields must have the data imported. This is probably very easy, but I am new at this. Is anyone able to tell me what I need to do? Thankyou. -
$fcontents = file ('mysqldata.csv');
-
-
for($i=0; $i<sizeof($fcontents); $i++) {
-
$line = trim($fcontents[$i]);
-
$arr = explode(',', $line);
-
-
$sql = "insert into results values ('','".implode("','",$arr)."')";
-
mysql_query($sql);
-
-
if(mysql_error()) {
-
echo mysql_error() ."<br>\n";
-
}
-
}
-
4 2960
If your data is in the correct field order, e.g. starting with field 5, you should use the columns specification of the MySQL INSERT statement. Hereby you specify the column names and in the order in which the values() should be inserted. Such as: - "insert into results (col5, col6, col7, col8,..... coln)
-
values ('".implode('",$arr)."')";
Ronald :cool:
Ok. I understand what you mean and can easily change the statement. However, the csv file which is being imploded still has those 1st 4 fields which I don't want inserted. Won't they be inserted even if I specify the column names? (Sorry if my questions seems stupid; I'm just trying to get my head around it.)
Oh good. Excellent. Thanks Ronald!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: robert |
last post by:
been ruminating on the question (mostly in a 390/v7 context) of
whether, and if so when, a row update becomes an insert/delete.
i assume that there is a threshold on the number of columns of
the...
|
by: James Butler |
last post by:
Our setup:
Online db: MySQL
Inhouse db: MS Access 97 with MySQL tables linked via ODBC
Our issue:
Almost every field updates successfully, except one.
A scenario:
Information is written to...
|
by: Maxi |
last post by:
I have 162 tables in my database. Names of the Tables are 1, 2, ......
so on till 162. Every table has only one field (field name = Expr2) of
type NUMBER (DOUBLE) with 352716 records in each table....
|
by: dhcomcast |
last post by:
We're starting to use Oracle for the back-end instead of a separate
Access .mdb file for the data and everything as gone surprisingly well
so far. We are learning Oracle as we go; Yikes! But we...
|
by: Lyners |
last post by:
I have a web page writen in ASP.NET that contains some javascript so that
when a user presses a button, or edits a certain field in a datagrid, another
cell in the datagrid is filled with a value....
|
by: mike11d11 |
last post by:
Our company has a collection system with a list of accounts in it, I
connect to this system with access using an ODBC connection. I pull in
the account #'s and other fields, then I have to run and...
|
by: Stephen Plotnick |
last post by:
I'm very new to VB.NET 2003
Here is what I have accomplished:
MainSelectForm - Selects an item
In a public class I pass a DataViewRow to
ItemInformation1 Form
ItemInformation2 Form
|
by: Ian Davies |
last post by:
Hello
Needing help with a suitable solution.
I have extracted records into a table under three columns 'category',
'comment' and share (the category column also holds the index no of the
record...
|
by: dougmeece |
last post by:
Morning Everyone...
I have a table that needs to be append to and also updated. All the fields in the table are populated with data from the text boxes and combo boxes on a form. The Date...
|
by: Neil |
last post by:
I'm running an update query in SQL 7 from QA, and it runs forever. Has been
running for 20 minutes so far! The query is quite simple: update a single
field in a table, based on a join with another...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |