当前位置:Gxlcms > PHP教程 > 怎样才能把全部的结果都输出

怎样才能把全部的结果都输出

时间:2021-07-01 10:21:17 帮助过:30人阅读

怎样才能把所有的结果都输出?
用ajax的post方法请求数据,回调函数里面怎样才能取出全部的数据。PS:(数据库里有多条数据 我这样写只能取出最后一条。)
前段代码:
$(document).ready(function() {
var submitData={
action:"SELECT",
};
$.post("../data/product_edit.php",submitData,function(data){
alert(data.product_type);
},"json");
});
后台代码:
dbconn();
$ACTION=$_POST['action'];
switch($ACTION) {
case "SELECT":
$sql="SELECT CLASSNAME FROM product_type";
$rs=mysql_query($sql);
while($row=mysql_fetch_array($rs)){
$arr=array(
'product_type'=>$row['CLASSNAME'],
);
}
} $json_string = json_encode($arr);
echo $json_string;
dbclose();
?>

分享到: 更多


------解决方案--------------------
$arr[]=array(
'product_type'=>$row['CLASSNAME']

赋值那块,改成这样试试。

人气教程排行