473,405 Members | 2,294 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.

Reading file character by character and stored into database

hello dr..........
i m trying to store a text file into database below format of text file
i hv text file like this:
0100102001110271 0409141151I1476201
0100102001110125 0409141351O1476301
0100101300000030 0409141630O1476401
0100102001110271 0409141631O1476501
0100102001110126 0409141632O1476601

how can store it into my database table att0310
my table fileds:
cardno date time IO(in-out) and serial no
0100102001110271 this is card no
040914 for date
1151 for time
I for IO
1476201 for serial no
plz help me out

till date data is inserted correctly into database but next data not stored into database. because of there is no space b/w those digits .... hw can i store that into database.... i tried so many times......... i used fopen function to read file character by character but i only display dat on browser not into database .. plz help me out......

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <?
  3. $con=mysql_connect("localhost","root","root");
  4. if (!$con)
  5. {
  6. die('Could not connect: ' . mysql_error());
  7. }
  8. mysql_select_db('test',$con);
  9. //(1) Read the text file into a variable
  10. $file=fopen("ATND.txt","r") or exit("Unable to open file!");
  11.  
  12. //(2) Then we can get rid of the tabs in there:
  13. $output = str_replace("\t"," ", $file);
  14. //(3) Then we explode it at every line break
  15. $output = explode("\n", $output);
  16. //(4) Then we loop through all the array elements and explode them again and insert them into mysql
  17. foreach($output as $var)
  18. {
  19. $tmp = explode(" ", $var);
  20. //$ecode = $tmp[0];
  21.  
  22.  
  23. $ecardno = $tmp[0];
  24. $atdate = $tmp[1];
  25. $attime = $tmp[2];
  26.  $IO = $tmp[3];
  27. $scode = $tmp[4];
  28. $sql = "INSERT INTO att SET  ecardno='$ecardno',atdate='$atdate',attime='$attime',IO='$IO',serialno='$serialno'";
  29. mysql_query($sql);
  30. }
  31. echo "Done!";
  32. mysql_close($con);
  33. ?>
  34. </html>
  35.  
Feb 22 '10 #1
2 1734
dlite922
1,584 Expert 1GB
You need substring





Dan
Feb 22 '10 #2
ok i do thanxxxxxxxxx
Feb 24 '10 #3

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

Similar topics

1
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but...
6
by: The_Kingpin | last post by:
Hi again guys, I've decided to cut my project in section and I found it way easier like this. I'm having a little problem reading struct in a file though. I think after this I'll be able to...
4
by: Andy | last post by:
Hello All: I have a field in the database that is an Image. I have no idea how the data is stored in here (Image, compressed, encrypted, plain text, etc). I am trying to write the contents to...
30
by: siliconwafer | last post by:
Hi All, I want to know tht how can one Stop reading a file in C (e.g a Hex file)with no 'EOF'?
18
by: John | last post by:
Hi, I'm a beginner is using C# and .net. I have big legacy files that stores various values (ints, bytes, strings) and want to read them into a C# programme so that I can store them in a...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
2
by: GeoUK | last post by:
Hi All, New member here with a bit of problem. I have read the FAQ's and searched text books but still cannot solve the problem that I have. As part of a course I am doing at University I had...
7
by: ianenis.tiryaki | last post by:
well i got this assignment which i dont even have a clue what i am supposed to do. it is about reading me data from the file and load them into a parallel array here is the question: Step (1) ...
11
by: Freddy Coal | last post by:
Hi, I'm trying to read a binary file of 2411 Bytes, I would like load all the file in a String. I make this function for make that: '-------------------------- Public Shared Function...
4
by: ramyakrishnakumar | last post by:
Hi All, I am facing some problem with basic file operation... I have one xml file looks like <?xml version="1.0" encoding="UTF-8" standalone="no" ?> <x:recording> <udf3>Gélin</udf3> ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
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,...

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.