Script PHP Select List Database Tabel Nama Propinsi di Indonesia

php_development

 

Tabel Propinsi:

[php]

CREATE TABLE `propinsi` (
`id_propinsi` int(10) NOT NULL AUTO_INCREMENT,
`nama_propinsi` varchar(100) NOT NULL,
PRIMARY KEY (`id_propinsi`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

[/php]

 

 

Berikut query insert untuk tabel propinsi

[php]

INSERT INTO `propinsi` (`id_propinsi`, `nama_propinsi`) VALUES
(11, ‘Nanggroe Aceh Darussalaam’),
(12, ‘Sumatra Utara’),
(13, ‘Sumatra Barat’),
(14, ‘Riau’),
(15, ‘Jambi’),
(16, ‘Sumatra Selatan’),
(17, ‘Bengkulu’),
(18, ‘Lampung’),
(19, ‘Kep. Bangka Belitung’),
(21, ‘Kep. Riau’),
(31, ‘DKI Jakarta’),
(32, ‘Jawa Barat’),
(33, ‘Jawa Tengah’),
(34, ‘DI Yogyakarta’),
(35, ‘Jawa Timur’),
(36, ‘Banten’),
(51, ‘Bali’),
(52, ‘Nusa Tenggara Barat’),
(53, ‘Nusa Tenggara Timur’),
(61, ‘Kalimantan Barat’),
(62, ‘Kalimantan Tengah’),
(63, ‘Kalimantan Selatan’),
(64, ‘Kalimantan Timur’),
(71, ‘Sulawesi Utara’),
(72, ‘Sulawesi Tengah’),
(73, ‘Sulawesi Selatan’),
(74, ‘Sulawesi Tenggara’),
(75, ‘Gorontalo’),
(81, ‘Maluku’),
(82, ‘Maluku Utara’),
(91, ‘Papua’),
(92, ‘Irian Jaya Barat’);

[/php]

 

Berikut script php select list propinsinya:

[php]

Baca Juga:

<?php require_once(‘Connections/koneksi.php’); ?>
<?php
if (!function_exists(“GetSQLValueString”)) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = “”, $theNotDefinedValue = “”)
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists(“mysql_real_escape_string”) ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case “text”:
$theValue = ($theValue != “”) ? “‘” . $theValue . “‘” : “NULL”;
break;
case “long”:
case “int”:
$theValue = ($theValue != “”) ? intval($theValue) : “NULL”;
break;
case “double”:
$theValue = ($theValue != “”) ? “‘” . doubleval($theValue) . “‘” : “NULL”;
break;
case “date”:
$theValue = ($theValue != “”) ? “‘” . $theValue . “‘” : “NULL”;
break;
case “defined”:
$theValue = ($theValue != “”) ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_koneksi, $koneksi);
$query_propinsi = “SELECT * FROM propinsi”;
$propinsi = mysql_query($query_propinsi, $koneksi) or die(mysql_error());
$row_propinsi = mysql_fetch_assoc($propinsi);
$totalRows_propinsi = mysql_num_rows($propinsi);
?><!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>

<body>
<form id=”form1″ name=”form1″ method=”post” action=””>
<select name=”select” id=”select”>
<?php
do {
?>
<option value=”<?php echo $row_propinsi[‘id_propinsi’]?>”><?php echo $row_propinsi[‘nama_propinsi’]?></option>
<?php
} while ($row_propinsi = mysql_fetch_assoc($propinsi));
$rows = mysql_num_rows($propinsi);
if($rows > 0) {
mysql_data_seek($propinsi, 0);
$row_propinsi = mysql_fetch_assoc($propinsi);
}
?>
</select>
</form>
</body>
</html>
<?php
mysql_free_result($propinsi);
?>

[/php]


Bagikan Artikel ini:
Facebook Twitter Blogger