Add serial number

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

Post Reply
sandy1028
Forum Commoner
Posts: 60
Joined: Thu Jul 26, 2007 3:56 am

Add serial number

Post 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]
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

do you have a database?

Post 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
sandy1028
Forum Commoner
Posts: 60
Joined: Thu Jul 26, 2007 3:56 am

Re: do you have a database?

Post 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
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Re: do you have a database?

Post 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.
sandy1028
Forum Commoner
Posts: 60
Joined: Thu Jul 26, 2007 3:56 am

Re: do you have a database?

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
Post Reply