471,336 Members | 1,297 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

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
Jul 17 '05 #1
6 4067
On 2005-01-26, matt <mc*****@gmail.com> wrote:
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!


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

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #2
Tim Van Wassenhove wrote:
On 2005-01-26, matt <mc*****@gmail.com> wrote:
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!

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

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?
Jul 17 '05 #3
On 2005-01-26, matt <mc*****@gmail.com> wrote:
Tim Van Wassenhove wrote:
On 2005-01-26, matt <mc*****@gmail.com> wrote:
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!

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

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?


Yes it's possible.

how do i go about finding the line numbers?


Count while you are reading.

or do it like this:

$file = '/tmp/test';

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

// output each line with it's linenumber
foreach($lines as $num => $val)
{
$val = htmlentities($val);
echo "<p><input type='radio' name='line' value='$num'>$val
</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_contents($file, implode("\n", $lines));


--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #4
matt wrote:
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!


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/

Jul 17 '05 #5
R. Rajesh Jeba Anbiah wrote:
matt wrote:
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!

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/

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...

Jul 17 '05 #6
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. . .

Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by amorphous999 | last post: by
9 posts views Thread by FFMG | last post: by
9 posts views Thread by =?Utf-8?B?TmF2YW5lZXRoLksuTg==?= | last post: by
15 posts views Thread by lxyone | last post: by

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.