473,396 Members | 1,816 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,396 software developers and data experts.

loop problem while the content of csv file is trying to insert into database

my code
Expand|Select|Wrap|Line Numbers
  1. <?
  2. //include("../mysqlconnect.php");
  3. $link = mysql_connect("localhost","root","")
  4.        or die("Could not connect: " . mysql_error());
  5.  mysql_select_db("suma");
  6.  
  7. include("include/upload.inc.php");
  8. if(isset($_POST['upload']))
  9. {
  10. $deli=$_POST['delimeter'];
  11.  
  12. $userfile=$_FILES['userfile']['name'];
  13. $userfile_tmp=$_FILES['userfile']['tmp_name'];
  14. $userfile_type=$_FILES['userfile']['type'];
  15. $userfile_size=$_FILES['userfile']['size'];
  16. $dir="upload";
  17. $filename=basename($userfile);
  18. move_uploaded_file("$userfile_tmp","$dir/$filename");
  19. $row= 1;
  20. $fp = fopen("$dir/$userfile", "r");
  21. $s="";
  22. $s1="";
  23. $s2="";
  24.  
  25. while (($data = fgetcsv($fp, 100000, "$deli")) !== FALSE) 
  26. {
  27.     $num = count($data);
  28.     $row++;
  29.     if($row==2)
  30.     {
  31.     for ($c=0; $c < $num; $c++) 
  32.     {
  33.         $s.=$data[$c]." VARCHAR (200) not null,";
  34.         $s2.=$data[$c].",";
  35.         $s1.="'$data[$c]',";
  36.     }
  37. echo      $sql="create table temp1(id int(20) not null auto_increment,".$s."extra varchar(200) not null, primary key(id))";
  38.     mysql_query($sql)or die("could not create");
  39.  
  40.      $sql1="insert into temp1 (".$s2."extra) values (".$s1."'choose')";
  41.     mysql_query($sql1)or die("could not insert");
  42.     }
  43.  
  44.     if($row > 2)
  45.     {
  46.     $s1="";
  47.     for ($c=0; $c < $num; $c++) 
  48.     {
  49.           $s1.="'$data[$c]',";
  50.     }
  51.      $sql2="insert into temp1 (".$s2."extra) values (".$s1."'choose')";
  52.     mysql_query($sql2)or die("could not insert");
  53.     }                
  54. }
  55.  
  56. fclose($fp);
  57. }
  58.  
  59. ?>
  60.  
  61. <table>
  62.  
  63. <form action="" method="post" enctype="multipart/form-data" name="form3" id="manu">
  64.  
  65.  <tr class="greyBG"> 
  66.       <td width="60%" height="33"> <div align="left">Please Enter the delimeter 
  67.         </div></td>
  68.       <td width="40%"><input type="text" name="delimeter"> </td>
  69.     </tr>
  70. <tr><td>Upload CSV file</td><td><input name="userfile" type="file"></td>
  71.  
  72.  
  73.  
  74.  
  75. </tr>
  76. <tr><td colspan="2">  <input type="submit" name="upload" value="upload"></td></tr>
  77. </form>
  78. </table>
[Please use CODE tags when posting source code. Thanks! --pbmods]
Jul 9 '07 #1
3 1821
pbmods
5,821 Expert 4TB
Heya, sumaabey.

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Jul 9 '07 #2
i want to import csv file into mysql data can you help me?
Jul 10 '07 #3
pbmods
5,821 Expert 4TB
Heya, sumaabey.

i want to import csv file into mysql data can you help me?
MySQL has a LOAD DATA INFILE command for that.
Jul 10 '07 #4

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

Similar topics

2
by: Jim | last post by:
Im getting way too many rows retured..what its trying to do is insert a 0 for revenue for months 7 - 12 (aka July through December) for each of these cost centers for each payor type..Im getting a...
1
by: ickypick | last post by:
I am writing a parser to read in ftp log files and insert into a databse. I have everything working fine, except the legacy billing system being used generates bills for each user instead of the...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
8
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
2
by: recordlovelife | last post by:
So I am trying to display a title, date, and content of a wordpress blog. Word press provides nice drop in functions to get the job done with simple names like "the_title", and the "the_content" But...
5
by: =?Utf-8?B?V2lsbGlhbSBGb3N0ZXI=?= | last post by:
Good evening all, I am trying to write a process that uses a while loop to cycle multiple files from an array throught the StreamReader Process. The whole thing works using: Dim...
1
by: Semajthewise | last post by:
Hi all!! What I am trying to do today is write to a textfile then read from the file get some lines from that file and edit them. and re-write them to the file. Not replace I want the edited lines...
10
by: cricket | last post by:
Hello, I am trying to create a loop in an MS Access application that will read in a list of iSeries system names from a file in my Access database, and then submit a command to each of the listed...
4
vikas251074
by: vikas251074 | last post by:
Loop runs indefinite times. suppose v_router = 5 is entered by user, then following code runs indefinite times i.e. record is inserted indefinite times though each have different i and v_ip_address....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.