14,695,615 members
See more:
Consider for example , If a person made a call for the first time then their caller id number appers to be a number (example-1).Suppose if the same person made a call for second time then their id number must appear as (example-1 (1)).

please specify the code for it in php

Id Name issue no
1 Abc 10
1(1) Abc 11
1(2) Abc 12
1(3) Abc 13
Posted
Updated 9-Oct-13 22:49pm
v5

## Solution 4

if(isset(\$_post['submit'])) //check if form has submitted or not

{
//gettting values from form elements,

\$name = \$_post['name'];
\$phn_nbr = \$_post['phn_nbr'];

\$sql=mysql_query("select * from tbl_name where phn_nbr='\$phn_nbr'");
\$res=mysql_fetch_array(\$sql);

// check if query is fetching records or not
if(\$res){
echo "phone number".\$phn_nbr."already exists in the name".\$name; // \$name is the name of the person fetched from table.
//insert the record as existing customer

//get previous value from name from table and take out last 3 numbers then add 1 then insert into table

```\$name1 =substr(\$name,-3);
echo \$name1;
\$name2 =\$name1+1;

if(strlen(\$name2)== '1')
{
\$name3 = '00'.\$name2;
}
else

if(strlen(\$name2)== '2')
{
\$name3 ='0'.\$name2;
}
else

if(strlen(\$name2)== '3')
{
\$name3 = \$name2;
}
echo \$name3;```

\$sql="insert into tbl (name,phn_br) values (\$name3,\$phn_nbr)";
\$res=mysql_query(\$sql);
}
else{
echo "phone number".\$phn_nbr."does not exists";

//insert the record as new customer by concatinating 001 for name

\$name1=\$name.'001';

```\$sql="insert into tbl (name,phn_br) values (\$name1,\$phn_nbr)";
\$res=mysql_query(\$sql);```

}

}

mysql_close()

?>

## Solution 2

At first time when the person calls you or at first time inserting values concatenate the name variable with 001 like \$name.'001'. For this you have to check the values in the table with the variable of inserting data based on phone number or any unique identity value for that person. By this you can easily find out existing person or new person.

Now If person is new then just concatenate the name variable with number 001 or if existing person then using substr function you can get the last 3 characters and add it with 1.
v3
nagaalekhya 10-Oct-13 7:37am

Thank you very much,

Can you pls write a small example program so that i will be very clear

pls narrate it with example