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);
?>
help on Automatic code generation...
Moderator: General Moderators
-
vsrivastava21
- Forum Newbie
- Posts: 1
- Joined: Fri Aug 15, 2008 1:07 pm
Re: help on Automatic code generation...
First of all, please use
Code: Select all
orCode: Select all
tags when posting your code, if its php code, preferCode: Select all
tags..Re: help on Automatic code generation...
And then, your code:
And when added {} to your first if and run through beautifier:
Code: Select all
<?php
$fn=$_POST["status"] // You're missing ; here, try after adding it
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);
?>
Code: Select all
<?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);
?>