
06-21-07, 11:41 AM
|
|
Coding Addict
|
|
Join Date: Jun 2005
Location: Singapore
Posts: 377
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi, I have another question.
It's about validating a csv file when uploaded. I tried this code, but doesn't work perfectly, so wanna check out where did I gone wrong or is there a better method.
The above is my current validation code. There is still some more to it, those seem to be alright. My main concern is the above codes. What I need is to check every row in the csv file and on each row, the first 3 column to see if there is any NULL value. If there is, then either reject the whole file OR upload only those that are without NULL values. (Not sure which is better).
If possible, I would also like to check exactly which ROW and COLUMN is missing and prompt the user about the particular missing ROW and COLUMN.
TIA.
|

06-21-07, 11:47 AM
|
 |
Community Liaison
|
|
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
|
|
i created a new thread of this post, as it has nothing to do with your old thread 
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks
|

06-21-07, 12:04 PM
|
|
Coding Addict
|
|
Join Date: Jun 2005
Location: Singapore
Posts: 377
Thanks: 0
Thanked 1 Time in 1 Post
|
|
|
|

06-21-07, 01:59 PM
|
 |
Community Liaison
|
|
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
|
|
If $temp contains the entire contents of the CSV file, and all records were seperated by \r\n,
then the foreach loop would put one record into $n each time. So you wouldn't need to explode
$n on \r\n because it only contains one record.
__________________
Jerry Broughton
|

06-21-07, 08:20 PM
|
|
Coding Addict
|
|
Join Date: Jun 2005
Location: Singapore
Posts: 377
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Thanks for the reply.
Yes, $temp contains the entire contents of the CSV file. Here's the code.
Actually, I don't really understand what is \r, can you explain to me?
After echoing message3, I'm doing some other validation. Should it fall under the for loop ? or outside the for loop better?
|

06-21-07, 11:45 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
__________________
Post a clear description of your problem, your code in code tags, your errors, and wait. Because nobody here's a mind reader...
|

06-22-07, 02:30 AM
|
|
Coding Addict
|
|
Join Date: Jun 2005
Location: Singapore
Posts: 377
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Isn't fgetcsv() also getting all the content in the csv file?
Right now, I need to validate the data, NOT getting the data.
|

06-22-07, 07:31 PM
|
 |
Community Liaison
|
|
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
|
|
Quote:
|
Actually, I don't really understand what is \r, can you explain to me?
|
\r is the symbol for a carriage return and the \n is the symbol for new line.
Some word processors use the \r and some use the \n for a new line.
So sometimes we use both \r\n just in case.
Here, check this out. What do you think?
I stored the contents of the file into a multi-dimensional array for later use.
Now you won't have to go back to the file. Everything is in the array $temp1.
I also tagged the end of each record with a 0 or 1 depending on the
value of $isTrue. You don't have to use it but it might come in handy later.
Or maybe like this. I'm not sure. You pick.
__________________
Jerry Broughton
Last edited by job0107; 06-22-07 at 07:56 PM.
|

06-24-07, 10:56 AM
|
|
Coding Addict
|
|
Join Date: Jun 2005
Location: Singapore
Posts: 377
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Thank You 0107, just saw your reply as I was out of town this weekend.
Will try out your suggestion tomorrow, getting late here now.
|

06-24-07, 01:59 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Nikas
Isn't fgetcsv() also getting all the content in the csv file?
Right now, I need to validate the data, NOT getting the data.
|
Not exactly. fgetcsv gets a single line at a time from a file and decodes it from csv to an array.
If your csv file should have 7 fields in it, you can do something like:
__________________
Post a clear description of your problem, your code in code tags, your errors, and wait. Because nobody here's a mind reader...
Last edited by Nico; 06-24-07 at 02:26 PM.
Reason: Please use [php] wrappers.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|