| | |
parsing csv file
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2005
Posts: 1
Reputation:
Solved Threads: 0
I am trying to Upload a csv file then split it up into an an array and build a query to insert it into a mysql table I have succeeded in getting this to work with one exception when I come across a field seperated by commas and enclosed by double quotes if that field also contains double quotes inside of it it throws off my column count I need to be able to consider something like - ,"sometext"some more text"additional text", as one field or value here is what i have so far
can anyone help? thanx
PHP Syntax (Toggle Plain Text)
$row = 1; $handle = fopen($uploadFile, "r"); while ( ($data = fgetcsv($handle, 10000, ",")) != FALSE ) { $num = count($data); if($row == 1){ $fields = " `id` , "; for($i=0; $i<$num; $i++){ $fields .= "`" . addslashes(trim($data[$i])) . "` , "; } $fields .= "`group` , `user` , "; $f = substr($fields, 0, -1); $f = substr($f, 0, -1); $row++; }else{ $values = " '' , "; for($i=0; $i<$num; $i++){ $values .= "'" . addslashes(trim($data[$i])) . "' , "; } $values .= "'personal' , '" . $_SESSION['user'] . "' , "; $v = substr($values, 0, -1); $v = substr($v, 0, -1); $sql = "INSERT INTO `addressbook` ( $f ) VALUES ( $v )"; mysql_query($sql) or die(print "<center><font size='2' face='verdana' color='#5E6B79'><b>Upload complete some entries may not have been loaded successfully!</b><br><br><a href='addressbook.php' class='light'>Back to Address Book</a></font></center></td></tr></table>"); $values = ''; $row++; } } fclose ($handle);
can anyone help? thanx
![]() |
Similar Threads
- Parsing a CSV File and inserting into a dictionary (Python)
- Parsing a CSV file separated by semicolons. (C++)
- csv file, ajax, php (PHP)
- parsing a csv file (PHP)
- Parsing a csv file in C (C)
- Parsing CSV file in partcular format (Java)
Other Threads in the PHP Forum
- Previous Thread: Need Web Based Contact Us Form
- Next Thread: http://www.ultracoder.com
| Thread Tools | Search this Thread |
5.2.10 action apache api array beginner binary broken cakephp checkbox class classes cms code cron curl database date destroy display dynamic echo echo$_get[x]changingitintovariable... email encode error fcc file files folder form forms function functions google header howtowriteathesis href htaccess html image images include insert ip javascript joomla limit link local login mail memberships menu mlm mod_rewrite multiple multipletables mysql mysqlquery network neutrality oop open passwords paypal pdf php provider query radio random record remote rss script search server sessions sockets source space sql strip_tags syntax system table template thesishelp tutorial update upload url validator variable video voteup web window.onbeforeunload=closeme; youtube





