Page 1 of 1

Add serial number

Posted: Tue Jul 31, 2007 11:37 pm
by sandy1028
feyd | Please use

Code: Select all

,

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 number

Code: 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

,

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]

do you have a database?

Posted: Tue Jul 31, 2007 11:48 pm
by yacahuma
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

Re: do you have a database?

Posted: Tue Jul 31, 2007 11:53 pm
by sandy1028
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

Re: do you have a database?

Posted: Wed Aug 01, 2007 12:13 am
by tecktalkcm0391
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.

Re: do you have a database?

Posted: Wed Aug 01, 2007 12:18 am
by sandy1028
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

Posted: Wed Aug 01, 2007 5:29 am
by onion2k
You're just quoting from a specification document or a school assignment aren't you? You really need to learn to ask questions properly.