Home > Backend Development > PHP Tutorial > Three-level linkage of provinces, cities and counties with mysql+ajax

Three-level linkage of provinces, cities and counties with mysql+ajax

WBOY
Release: 2016-07-25 09:01:19
Original
1012 people have browsed it

In PHP development, I want to write a mysql+ajax three-level linkage between provinces, cities and counties. Everything has been written, and I am just waiting to return data in xml or json format.

The query is: $sql="select * from cities where sid=1";//1 is the ID of Jiangsu Province. Needless to say this

$res=mysql_query($sql);

How to deal with the following, use a while loop or how to do it? The xml format I want is similar to

NanjingSuzhou

Reprinted from other people’s questions and answers. . .

  1. I will send you the code including the database once to express my gratitude! ! !
  2. php page:
  3. //The two sentences here are very important. The first sentence tells the browser that the data returned is in xml format
  4. header("Content-Type: text/html;charset=utf-8") ;
  5. //Tell the browser not to cache data
  6. header("Cache-Control: no-cache");
  7. $conn=mysql_connect("localhost","root","123");
  8. mysql_select_db("ajax") ;
  9. mysql_query("set names utf8");
  10. if(isset($_POST['sid'])){
  11. $sid=$_POST['sid'];
  12. //file_put_contents("D:/a. txt",$sid);
  13. $sql_shi="select shi from shi where sid=$sid";
  14. $res_shi=mysql_query($sql_shi);
  15. $arr="";
  16. while($row=mysql_fetch_array($res_shi )){
  17. $arr[]=$row;
  18. }
  19. $a=json_encode($arr);
  20. echo '{"aa":'.$a.'}';
  21. }
  22. ?>
  23. js page :
  24. html page:
Copy code
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template