<?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; } } ?>