On Friday 20 August 2004 16:28, Dustin Wish with INDCO Networks wrote: > I was curious if anyone could help me. I need to write an insert to take > data from a csv file to put into a MySQL db. I am not sure know to parse > out 5 items of the string at a time i.e. (1,2,3,4,5,1,2,3,4,5,1...etc) so > that the five putted items get inserted everytime. Like:
Check http://bu.orbitel.bg/fgetcsvfromline.php and http://bu.orbitel.bg/csv.php I'm sure they will help you. I've posted this in PHP's manual fgetcsv function. > > "insert into products (item,price,rate,name,desc) values (1,2,3,4,5)" > > Then on to the next one and so forth. > > I am already parsing the file, but not sure if it needs to go into an array > or set to vars then done in a loop. > > Please help! > > Here is the script so far: > > <? > $filename = "inventory.csv"; > $fd = fopen ($filename, "r"); > $contents = fread ($fd,filesize ($filename)); > > fclose ($fd); > $delimiter = ","; > $splitcontents = explode($delimiter, $contents); > $counter = "5"; > ?> > <br><br> > <font color="blue" face="arial" size="4">Database Insert Script</font> > <hr> > <? > foreach ( $splitcontents as $color ) > { > > $counter = $counter+1; > echo "<b>Line Item $counter: </b> $color\n<br>"; > > > > } > ?> > <hr> > > > > Dustin Wish > System Engineer & Programmer > INDCO Networks > Pres. OSSRI > Pres. WTA Arkansas > ******************************************************** > "Do not go where the path may lead, go instead > where there is no path and leave a trail." > Ralph Waldo Emerson (1803-1882) > *********************************************** -- Cyberly yours, Petar Nedyalkov Devoted Orbitel Fan :-) --------------------------------------------------------------------- Orbitel - the New Generation Telecom! See www.orbitel.bg. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php