473,405 Members | 2,310 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,405 software developers and data experts.

update all fields except 1st 5

170 100+
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.

Expand|Select|Wrap|Line Numbers
  1. $fcontents = file ('mysqldata.csv'); 
  2.  
  3.   for($i=0; $i<sizeof($fcontents); $i++) { 
  4.       $line = trim($fcontents[$i]); 
  5.       $arr = explode(',', $line); 
  6.  
  7.       $sql = "insert into results values ('','".implode("','",$arr)."')"; 
  8.       mysql_query($sql);
  9.  
  10.       if(mysql_error()) {
  11.          echo mysql_error() ."<br>\n";
  12.       } 
  13. }
  14.  
Dec 11 '06 #1
4 2960
ronverdonk
4,258 Expert 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. "insert into results (col5, col6, col7, col8,..... coln) 
  2.               values ('".implode('",$arr)."')";
Ronald :cool:
Dec 11 '06 #2
beary
170 100+
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.)
Dec 11 '06 #3
ronverdonk
4,258 Expert 4TB
Get the first 4 array entries out by using PHP array functions, i.e. the array_shift() function. See http://nl3.php.net/manual/en/function.array-shift.php

Ronald :cool:
Dec 12 '06 #4
beary
170 100+
Oh good. Excellent. Thanks Ronald!
Dec 12 '06 #5

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

Similar topics

16
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...
9
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...
5
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....
4
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...
13
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....
2
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...
5
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
16
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...
4
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...
13
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...
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: 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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...

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.