PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
sandy1028
Forum Commoner
Posts: 60 Joined: Thu Jul 26, 2007 3:56 am
Post
by sandy1028 » Tue Jul 31, 2007 11:37 pm
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
How to add the serial number to txt file as auto increment when the new data is entered.
Is there any any to auto increment the serial numberCode: Select all
<?php
$name=$_POST['name'];
$data="$name";
$fp= fopen("data.txt","a") or die("can't open file");
fwrite($fp, $data);
fclose($fp); }
?>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
yacahuma
Forum Regular
Posts: 870 Joined: Sun Jul 01, 2007 7:11 am
Post
by yacahuma » Tue Jul 31, 2007 11:48 pm
you could use a database to get the next number.
you could read the whole directory and determine the next number. only if you know that only one file will be created at a time(single user system)
you could create some kind of lock file, where the lock file has the next number. you have to lock and unlock the file in a multi user system
sandy1028
Forum Commoner
Posts: 60 Joined: Thu Jul 26, 2007 3:56 am
Post
by sandy1028 » Tue Jul 31, 2007 11:53 pm
yacahuma wrote: you could use a database to get the next number.
you could read the whole directory and determine the next number. only if you know that only one file will be created at a time(single user system)
you could create some kind of lock file, where the lock file has the next number. you have to lock and unlock the file in a multi user system
Is there any way to add serial number in text file of php
tecktalkcm0391
DevNet Resident
Posts: 1030 Joined: Fri May 26, 2006 9:25 am
Location: Florida
Post
by tecktalkcm0391 » Wed Aug 01, 2007 12:13 am
sandy1028 wrote: yacahuma wrote: you could use a database to get the next number.
you could read the whole directory and determine the next number. only if you know that only one file will be created at a time(single user system)
you could create some kind of lock file, where the lock file has the next number. you have to lock and unlock the file in a multi user system
Is there any way to add serial number in text file of php
Don't get what your asking. Yes, you could make a serial number in a .txt file or make a .php file... whatever you want.
sandy1028
Forum Commoner
Posts: 60 Joined: Thu Jul 26, 2007 3:56 am
Post
by sandy1028 » Wed Aug 01, 2007 12:18 am
tecktalkcm0391 wrote: sandy1028 wrote: yacahuma wrote: you could use a database to get the next number.
you could read the whole directory and determine the next number. only if you know that only one file will be created at a time(single user system)
you could create some kind of lock file, where the lock file has the next number. you have to lock and unlock the file in a multi user system
Is there any way to add serial number in text file of php
Don't get what your asking. Yes, you could make a serial number in a .txt file or make a .php file... whatever you want.
When I enter the $data into file serial number should be added.
For eg:when data entered is aaa
bbb
In the file it should be
1. aaa
2 bbb
3 ccc
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Wed Aug 01, 2007 5:29 am
You're just quoting from a specification document or a school assignment aren't you? You really need to learn to ask questions properly.