-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefecture_data.php
65 lines (49 loc) · 1.76 KB
/
prefecture_data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
require_once('DB_connection.php');
require_once('select_box.php');
//非汎用的実装
class Prefecture_Data {
private static $_PREFECTURES = array(0 => '--');
private static $_isLoaded = false;
//DBのdsn・userを設定
private static $_dsn = 'mysql:dbname=firstDB;host=127.0.0.1';
private static $_user = 'root';
private static function _loadPrefectures() {
$connection = DB_Connection::getInstance(self::$_dsn, self::$_user);
$pdo = $connection->getPDO();
$sql = "
SELECT
pref_id, pref_name
FROM
prefecture_info
";
$query = $pdo->prepare($sql);
$query->execute();
self::_createPrefectureList($query);
self::$_isLoaded = true;
}
//ロード用モジュール
private static function _createPrefectureList($query) {
$record;
while(($record = $query->fetch()) != false) {
$pref_id = intval($record[0]);
$pref_name = $record[1];
$add = array($pref_id => $pref_name);
self::$_PREFECTURES += $add;
}
}
//htmlの要素のパラメータを設定
public static function constructSelectBox($value) {
if(self::$_isLoaded == false) self::_loadPrefectures();
$name = 'prefecture';
$id = 'prefecture';
$size = 1;
$prefecture_box = new Select_Box($name, $id, $size, self::$_PREFECTURES, $value);
$prefecture_box->construct($value);
}
public static function getPrefectureID($pref_name) {
if(self::$_isLoaded == false) self::_loadPrefectures();
$pref_id = array_keys(self::$_PREFECTURES, $pref_name)[0];
return $pref_id;
}
}