$sql_isi ="SELECT * FROM $tabel";
$qr_isi =mysql_query($sql_isi) or die ("Gagal query".mysql_error());
if (mysql_num_rows($qr_isi) <=0) {
$id_berita=$inisial."001";
}
else {
$sql_idberita="SELECT count(*) + 1 AS kd_admin FROM $tabel";
$qr_idberita=@mysql_query($sql_idberita) or die ("Gagal query".mysql_error());
$hs_idberita=mysql_fetch_array($qr_idberita) or die ("Hasil pemakai tidak ada");
$kd_admin=$hs_idberita[kd_admin];
if ($kd_admin < 10 ) {
$id_berita=$inisial."0000".$kd_admin;
}
elseif ($kd_admin < 100) {
$id_berita=$inisial."000".$kd_admin;
}
elseif ($kd_admin < 1000) {
$id_berita=$inisial."00".$kd_admin;
}
elseif ($kd_admin < 10000) {
$id_berita=$inisial."0".$kd_admin;
}
elseif ($kd_admin < 100000) {
$id_berita=$inisial.$kd_admin;
}
}
0 komentar: