Reading file character by character and stored into database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • puneetmca
    New Member
    • Jan 2010
    • 15

    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:
    010010200111027 1 0409141151I1476 201
    010010200111012 5 0409141351O1476 301
    010010130000003 0 0409141630O1476 401
    010010200111027 1 0409141631O1476 501
    010010200111012 6 0409141632O1476 601

    how can store it into my database table att0310
    my table fileds:
    cardno date time IO(in-out) and serial no
    010010200111027 1 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......

    [code=php]
    <html>
    <?
    $con=mysql_conn ect("localhost" ,"root","root") ;
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db ('test',$con);
    //(1) Read the text file into a variable
    $file=fopen("AT ND.txt","r") or exit("Unable to open file!");

    //(2) Then we can get rid of the tabs in there:
    $output = str_replace("\t "," ", $file);
    //(3) Then we explode it at every line break
    $output = explode("\n", $output);
    //(4) Then we loop through all the array elements and explode them again and insert them into mysql
    foreach($output as $var)
    {
    $tmp = explode(" ", $var);
    //$ecode = $tmp[0];


    $ecardno = $tmp[0];
    $atdate = $tmp[1];
    $attime = $tmp[2];
    $IO = $tmp[3];
    $scode = $tmp[4];
    $sql = "INSERT INTO att SET ecardno='$ecard no',atdate='$at date',attime='$ attime',IO='$IO ',serialno='$se rialno'";
    mysql_query($sq l);
    }
    echo "Done!";
    mysql_close($co n);
    ?>
    </html>
    [/code]
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    You need substring





    Dan

    Comment

    • puneetmca
      New Member
      • Jan 2010
      • 15

      #3
      ok i do thanxxxxxxxxx

      Comment

      Working...