jquery+ajax实现省市区三级联动 (封装和不封装两(2)

<?php $code=$_POST["code"]; require "DB.class.php"; $db=new DB(); $sql="select areacode,areaname from chinastates where parentareacode='{$code}'"; $str=$db->strquery($sql); echo $str;

最后就是封装的类文件:DB.class.php

function strquery($sql) { $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname); $result = $db ->query($sql); $arr =$result->fetch_all(); $str=""; foreach($arr as $v) { $str=$str.implode("^",$v)."|"; } $str = substr($str,0,strlen($str)-1); return $str; } } ?>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wysfwy.html