PHP Flat File Database - How to Load and Edit Lines?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • matt

    #1

    PHP Flat File Database - How to Load and Edit Lines?

    I am using a text file as a database, each field delimited by ||
    I want to be able to print all lines to a page, then by selecting one
    (with, say, a radio button) it will load into the form at the bottom of
    the page, where I can edit the fields, and save back to the same line in
    the text file.

    I dont know how to use primary keys or anything with a text file
    database, any help in this would be appreciated!
    Thanks
    matt
  • Tim Van Wassenhove

    #2
    Re: PHP Flat File Database - How to Load and Edit Lines?

    On 2005-01-26, matt <mcpaton@gmail. com> wrote:[color=blue]
    > I am using a text file as a database, each field delimited by ||
    > I want to be able to print all lines to a page, then by selecting one
    > (with, say, a radio button) it will load into the form at the bottom of
    > the page, where I can edit the fields, and save back to the same line in
    > the text file.
    >
    > I dont know how to use primary keys or anything with a text file
    > database, any help in this would be appreciated![/color]

    Well, you could consider each line to be unique by it's linenumber.



    --
    Met vriendelijke groeten,
    Tim Van Wassenhove <http://www.timvw.info>

    Comment

    • matt

      #3
      Re: PHP Flat File Database - How to Load and Edit Lines?

      Tim Van Wassenhove wrote:[color=blue]
      > On 2005-01-26, matt <mcpaton@gmail. com> wrote:
      >[color=green]
      >>I am using a text file as a database, each field delimited by ||
      >>I want to be able to print all lines to a page, then by selecting one
      >>(with, say, a radio button) it will load into the form at the bottom of
      >>the page, where I can edit the fields, and save back to the same line in
      >>the text file.
      >>
      >>I dont know how to use primary keys or anything with a text file
      >>database, any help in this would be appreciated![/color]
      >
      >
      > Well, you could consider each line to be unique by it's linenumber.
      >
      >
      >[/color]
      ok, but is it possible to do it all in one page, select from the list,
      load it back into the form at the bottom, and then save back over
      itself? how do i go about finding the line numbers?

      Comment

      • Tim Van Wassenhove

        #4
        Re: PHP Flat File Database - How to Load and Edit Lines?

        On 2005-01-26, matt <mcpaton@gmail. com> wrote:[color=blue]
        > Tim Van Wassenhove wrote:[color=green]
        >> On 2005-01-26, matt <mcpaton@gmail. com> wrote:
        >>[color=darkred]
        >>>I am using a text file as a database, each field delimited by ||
        >>>I want to be able to print all lines to a page, then by selecting one
        >>>(with, say, a radio button) it will load into the form at the bottom of
        >>>the page, where I can edit the fields, and save back to the same line in
        >>>the text file.
        >>>
        >>>I dont know how to use primary keys or anything with a text file
        >>>database, any help in this would be appreciated![/color]
        >>
        >>
        >> Well, you could consider each line to be unique by it's linenumber.
        >>
        >>
        >>[/color]
        > ok, but is it possible to do it all in one page, select from the list,
        > load it back into the form at the bottom, and then save back over
        > itself?[/color]

        Yes it's possible.

        [color=blue]
        > how do i go about finding the line numbers?[/color]

        Count while you are reading.

        or do it like this:

        $file = '/tmp/test';

        // read file into array
        $lines = explode("\n", file_get_conten ts($file));

        // output each line with it's linenumber
        foreach($lines as $num => $val)
        {
        $val = htmlentities($v al);
        echo "<p><input type='radio' name='line' value='$num'>$v al
        </p>";
        }

        // now manipulate the $lines array
        .....

        // write array into file - might want to read the manual if you're not
        // using php5 for an alternative
        file_put_conten ts($file, implode("\n", $lines));




        --
        Met vriendelijke groeten,
        Tim Van Wassenhove <http://www.timvw.info>

        Comment

        • R. Rajesh Jeba Anbiah

          #5
          Re: PHP Flat File Database - How to Load and Edit Lines?

          matt wrote:[color=blue]
          > I am using a text file as a database, each field delimited by ||
          > I want to be able to print all lines to a page, then by selecting one[/color]
          [color=blue]
          > (with, say, a radio button) it will load into the form at the bottom[/color]
          of[color=blue]
          > the page, where I can edit the fields, and save back to the same line[/color]
          in[color=blue]
          > the text file.
          >
          > I dont know how to use primary keys or anything with a text file
          > database, any help in this would be appreciated![/color]

          Don't invent your own flat file DB. There are plenty of such works
          available.

          You may also try PHP way:
          1. http://in.php.net/var_export with include()
          2. http://in.php.net/serialize and unserialize()

          --
          <?php echo 'Just another PHP saint'; ?>
          Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

          Comment

          • matt

            #6
            Re: PHP Flat File Database - How to Load and Edit Lines?

            R. Rajesh Jeba Anbiah wrote:[color=blue]
            > matt wrote:
            >[color=green]
            >>I am using a text file as a database, each field delimited by ||
            >>I want to be able to print all lines to a page, then by selecting one[/color]
            >
            >[color=green]
            >>(with, say, a radio button) it will load into the form at the bottom[/color]
            >
            > of
            >[color=green]
            >>the page, where I can edit the fields, and save back to the same line[/color]
            >
            > in
            >[color=green]
            >>the text file.
            >>
            >>I dont know how to use primary keys or anything with a text file
            >>database, any help in this would be appreciated![/color]
            >
            >
            > Don't invent your own flat file DB. There are plenty of such works
            > available.
            >
            > You may also try PHP way:
            > 1. http://in.php.net/var_export with include()
            > 2. http://in.php.net/serialize and unserialize()
            >
            > --
            > <?php echo 'Just another PHP saint'; ?>
            > Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
            >[/color]
            i already have it adding records, and erasing records, but i just want
            to be able to edit records (or lines) and save back over itself...

            i've tried to use 1 page to select the line to edit, then send that info
            to another page to edit it, but i'm not winning...

            Comment

            • artlangs

              #7
              Re: PHP Flat File Database - How to Load and Edit Lines?

              Try changing the db format to arrays and serialize it -- which will be
              indexed by their numberical keys. Then you open the file, unserialize
              it, loop to output the key, and the other info, maybe include a hidden
              field with the value of the key, and then when you submit it to edit
              it, load the stuff with that key. . .

              Comment

              Working...