By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,548 Members | 1,735 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,548 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.