help on Automatic code generation...
Posted: Fri Aug 15, 2008 1:16 pm
I have created a function to create an automatic code i.e. like employee code, customer code or seeker code etc. I have some problem while writing code , please help somebody...
I also fetching the values from database to generate code.
Please help me out... its urgent...
regards
Vivek
<?php
$fn=$_POST["status"]
function newCode($fn)
{
$db="scientist";
$link=mysql_connect("localhost","root","admin");
if(!$link)
die("could not connect to mysql".mysql_error());
mysql_select_db($db,$link) or die("could not connect to $db".mysql_error());
$result=mysql_query("select * from code_generate where field_name='$fn'");
while($row=mysql_fetch_array($result))
{
$autoGen=$row[1];
echo $autoGen;
if($autoGen.equals("N"))
{
$newcode="" ;
}
else
{
$fp=$row[2]; //fetching prefix from table.
$tp=(String)$row[4]; //fetching current_no from table.
$tempCode=$fp+$tp;
$num=(int)$row[3]-strlen($tempCode); //fetching length from table.
$temp="000000000000";
$sp=temp.substr(0,$num);
$newcode=$fp+$sp+$tp;
echo $newCode;
}
}
return $newcode;
}
$code=newCode($fn);
?>
I also fetching the values from database to generate code.
Please help me out... its urgent...
regards
Vivek
<?php
$fn=$_POST["status"]
function newCode($fn)
{
$db="scientist";
$link=mysql_connect("localhost","root","admin");
if(!$link)
die("could not connect to mysql".mysql_error());
mysql_select_db($db,$link) or die("could not connect to $db".mysql_error());
$result=mysql_query("select * from code_generate where field_name='$fn'");
while($row=mysql_fetch_array($result))
{
$autoGen=$row[1];
echo $autoGen;
if($autoGen.equals("N"))
{
$newcode="" ;
}
else
{
$fp=$row[2]; //fetching prefix from table.
$tp=(String)$row[4]; //fetching current_no from table.
$tempCode=$fp+$tp;
$num=(int)$row[3]-strlen($tempCode); //fetching length from table.
$temp="000000000000";
$sp=temp.substr(0,$num);
$newcode=$fp+$sp+$tp;
echo $newCode;
}
}
return $newcode;
}
$code=newCode($fn);
?>