473,233 Members | 1,602 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,233 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 4227
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: amorphous999 | last post by:
I want to use DTS to load from a flat file. But I can't be sure when the flat file will arrive. I would like the job to check every 10 minutes or so for a couple of hours. If the file is...
4
by: Ben | last post by:
So, at my place of employment, we use a national standard to transmit data between certain applications. This standard consists of a fixed width, flat file 4500-some-odd chars wide that contain...
3
by: blackd77 | last post by:
What I would LIKE to do is noted in the subject line. What I'm finding is that "edit SQL" appears to only be an option if I am creating a table. If I select "append to" the option to edit SQL...
14
by: vunet.us | last post by:
Hi, I would like to use flat file data storage instead of database. Since I am new to it, I am wondering: What text file extension is a safe one to store my data online and how cost- and...
9
by: FFMG | last post by:
In my site I have a config table, (MySQL), with about 30 entries; the data is loaded on every single page load. This is not the only call to the db, (we do a total of about 8 calls to the db). As...
5
by: deppeler | last post by:
Can someone look at this for me: I am trying to set up a script to edit an item in a flat file DB but I don't seem to be getting the data to the Photoedit script. It seems to be reading the 1st line...
9
by: =?Utf-8?B?TmF2YW5lZXRoLksuTg==?= | last post by:
Hello I am developing a system for user tracking. In this I am tracking all the visitors that came to my website. i developed this using a HTTPModule and storing the data in a SQL Server...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
3
by: Flugeldorph | last post by:
I am new to Visual Basic, my preferred languages is C or C++. I am trying to load a local database with data that I am reading from a delimited flat file. I have created the database tables and...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.