473,407 Members | 2,546 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,407 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 4240
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.