Banyak banget yang tanya tentang Nomor Otomatis di PHP, padahal tinggal cari di mas GOOGLE. tapi ini dunia Open Source Man.....
Coba script ini :
function cuhe_num($field,$table,$key,$Parse,$Digit_Count)
{
$NOL="0";
$Q = mysql_query("Select $field from $table where $key like '$Parse%' order by $key DESC") or die(mysql_error()."Select $field from $table where $key like '$Parse%' order by $key DESC");
$N = mysql_affected_rows();
$counter=2;
if($N==0)
{
while($counter < $Digit_Count)
{
$NOL="0".$NOL;
$counter++;
}
return $Parse.$NOL."1";
}
else
{
$R = mysql_fetch_row($Q);
$K = sprintf("%d",substr($R[0],-$Digit_Count));
$K = $K + 1;
$L = $K;
while(strlen($L)!=$Digit_Count)
{
$L = "0".$L;
}
return $Parse.$L;
}
}
?>
gimana cara pake nya????
nih !!!!
echo cuhe_num("id","table","id","Cuhe",5);
ntar tampilan-nya :
Cuhe00001
Minggu, 13 April 2008
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar