Three-level linkage display information of Chinese provinces and cities

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

  

Processing interface

<?php    include ("dbda.php"), $db =new Dbda (); $pcode =$_post["Pcode"]; $sql = "SELECT * from Chinastates where Parentareacode = ' {$pcode} ', Echo $db->strquery ($sql);

  

Encapsulate Class Code

<?phpclass dbda{public $host = "localhost";//server address public $uid = "root";//user name public $pwd = "";//password public $conn;//Connection object// How to manipulate the database//$SQL represents the SQL statement that needs to be executed//$type represents the type of SQL statement, 1 for the query, 0 for the delete//$DB represents the database name to manipulate//if it is a query, returns a two-dimensional array//if it is another statement, Returns TRUE or Falsefunction __construct ($db = "AAAS") {//Build Connection object $this->conn = new Mysqli ($this->host, $this->uid,$ This->pwd, $db);} Public Function Query ($sql, $type =1) {//Determine if error!mysqli_connect_error () or Die ("Connection failed! ");//Execute SQL statement $result = $this->conn->query ($sql);//Determine SQL statement type if ($type ==1) {///If it is a query statement, returns a two-dimensional array of result sets return $result- >fetch_all ();} else{//if it is a different statement, returns TRUE or Falsereturn $result;}} The AJAX call returns Jsonpublic function Jsonquery ($sql, $type =1, $db = "AAAS") {//define data source $dsn = "mysql:dbname={$db};host={$this- >host} ";//Create PDO object $pdo = new PDO ($dsn," {$this->uid} "," {$this->pwd} ");//prepare to execute SQL statement $st = $pdo->prepare ($sql) ;//execute preprocessing SQL statement if ($st->execute ()) {if ($type ==1) {$sttr = $st->fetchall (PDO::FETCH_ASSOC); return Json_encode ($ attr);} Else{if ($st) {return "OK";} Else{return "NO";}}} Else{echo "Execution failed!";}} The AJAX call returns the string public function strquery ($sql, $type =1) {//determines if the connection was successful!mysqli_connect_error () or Die ("Connection failed! ");//Execute SQL statement $result = $this->conn->query ($sql);//Determine SQL statement type if ($type ==1) {$attr = $result->fetch_all (); $str = "";//If the query statement returns a string for ($i =0; $i <count ($attr); $i + +) {for ($j =0; $j <count ($attr [$i]); $j + +) {$str = $str. $attr [$i][$ j]; $str = $str. " ^";} $str = substr ($str, 0,strlen ($STR)-1); $str = $str. "|";} $str = substr ($str, 0,strlen ($STR)-1); return $str;} else{//if it is a different statement, return TRUE or Falseif ($result) {return "OK";} Else{return "NO";}}} function Pdoquery ($sql, $type =1, $db = "AAAS") {//build data source $dns = "mysql:host={$this->host};d bname={$db}";//PDO Object $PDO = New PDO ($dns, $this->uid, $this->pwd);//prepare an SQL statement $stm = $pdo->prepare ($sql);//execute preprocessing statement = $stm->execute () if ($r) {if ($type ==1) {return $stm->fetchall ();} Else{return "OK";}} Else{return "NO";}}}

  

Three-level linkage display information of Chinese provinces and cities

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.