Click here to Skip to main content
14,695,615 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 9-Oct-13 22:49pm

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'");

// check if query is fetching records or not
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;

    if(strlen($name2)== '2')
        $name3 ='0'.$name2;

    if(strlen($name2)== '3')
        $name3 = $name2;
echo $name3;

$sql="insert into tbl (name,phn_br) values ($name3,$phn_nbr)";
echo "phone number".$phn_nbr."does not exists";

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


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




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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900