Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Anar Samadov committed Mar 22, 2018
1 parent a27ec34 commit 782878c
Show file tree
Hide file tree
Showing 7 changed files with 431 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .idea/ders.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

232 changes: 232 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
@@ -1,2 +1,2 @@
# php-pdo-mysql-bolge-il-ilce
# Dinamik bölge, il ve ilçe combobox uygulaması
PHP PDO ile MySQL veritabanından Bölge, İl ve ilçe bilgilerini çekerek dinamik combobox uygulaması yapmak.
24 changes: 24 additions & 0 deletions ajax.php
@@ -0,0 +1,24 @@
<?php
include ("dbConn.php");

$action=$_POST["action"];

switch ($action)
{
case "bolge":
$db=new dbConn();
return $db->getBolgeList();
break;

case "il":
$db=new dbConn();
$bolge=$_POST["name"];
return $db->getIlList($bolge);
break;

case "ilce":
$db=new dbConn();
$il=$_POST["name"];
return $db->getIlceList($il);
break;
}
72 changes: 72 additions & 0 deletions dbConn.php
@@ -0,0 +1,72 @@
<?php
/**
* Created by PhpStorm.
* User: user
* Date: 3/22/2018
* Time: 22:19
*/

class dbConn
{
protected static $db;


//veritabanına bağlanan fonksiyon
public function __construct()
{
try{
self::$db = new PDO("mysql:host=localhost;dbname=ililce;charset=utf8", "root", "123456");
}
catch (PDOException $exception)
{
print $exception->getMessage();
}
}

//Bölgeleri getiren fonksiyon
public function getBolgeList()
{
$data=array();
$query = self::$db->query("SELECT DISTINCT bolge from ilveilceler", PDO::FETCH_ASSOC);
if($query->rowCount())
{
foreach ($query as $row)
{
$data[]=$row["bolge"];
}
}
echo json_encode($data);
}


//İlleri getiren fonksiyon
public function getIlList($bolge){
$data=array();
$query = self::$db->prepare("SELECT DISTINCT il FROM ilveilceler WHERE bolge=:bolge");
$query->execute(array(":bolge"=>$bolge));
if($query->rowCount())
{
foreach ($query as $row)
{
$data[]=$row["il"];
}
}
echo json_encode($data);
}


//İlçeleri getiren fonksiyon
public function getIlceList($il){
$data=array();
$query = self::$db->prepare("SELECT DISTINCT ilce FROM ilveilceler WHERE il=:il");
$query->execute(array(":il"=>$il));
if($query->rowCount())
{
foreach ($query as $row)
{
$data[]=$row["ilce"];
}
}
echo json_encode($data);
}
}

0 comments on commit 782878c

Please sign in to comment.