Database, php, and ajax-based regional linkages

Source: Internet
Author: User
: This article mainly introduces three levels of regional linkages based on databases, php, and ajax. For more information about PHP tutorials, see.

Previously, the multi-level linkage of JavaScript code written by others was basically used for each use of regional linkage. However, the biggest drawback was that the region information was too old and inconvenient to update.
Today, I searched online for the latest country and region information data in 2015. I plan to use the database and ajax for linkage. the background can also easily update the data.

Code 1 (jquery code, in charge of the ajax data Association section ):


  
   
    
Province
    
     
      
// Volist is the tag of thinkphp. here I use the code written in the thinkphp framework to automatically load the information of provincial regions.
      
       
         {$ Vo. class_name}
        
          City
         
          
            County/district
           
            

Code 2 (php backend data judgment interactive code, written based on thinkphp. if it is another framework, the principle is the same, and the code will be slightly different ):

Publicfunctionajax () {$ city = M ('city'); if (! IS_AJAX) {$ this-> ajaxReturn (array ('info' => 'Invalid request method '));} // if the submitted province changes if (I ('post. province ', 0, 'intval') {$ filter = array ('class _ parent_id' => I ('post. province ', 0, 'intval'), 'class _ type' => 2); $ data ['content'] = $ city-> where ($ filter) -> select (); $ data ['info'] = 'OK';} // if the submitted result is a city change if (I ('post. city ', 0, 'intval') {$ filter = array ('class _ parent_id' => I ('post. city ', 0, 'intval'), 'class _ type' => 3); $ data ['content'] = $ city-> where ($ filter) -> select (); $ data ['info'] = 'OK';} $ this-> ajaxReturn ($ data );}

The last is the database, which contributed its own database. it was written according to the regional information published by the state in January 2015 and is the latest.

SQL database download

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above section describes the three-level regional linkages based on databases, php, and ajax, including the content, and hopes to help those who are interested in PHP tutorials.

    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.