: 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.