连接方法:$db=mysqli_connect("127.0.0.1","用户名","密码","数据库名")or die("Mysql连接失败" . mysqli_connect_error());
$sql="sql语句";
$res=$db->query($sql);
$str='';
foreach($res as $k => $v){
$str .=implode(',',$v) . '-';
}
$str =substr($str ,0, strlen($str) -1);
echo $str;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
输出json格式
$arr=array();
foreach($res as $k => $v){
if($v['open']==0){
$list[$k]['id'] = $v['id'];
箭值对格式
}
$list[$k]['id'] = $v['id'];
}
$json =json_encode($list);
echo $json;
-----------------------------------------------------------------------------------------------------------------------------------
ajax返回在页面上输出
function fangru(arr){
//arrj就是查出来的数据以‘-’分割
var brr=[];
var str ="";
for(var i =0;i<arr.length;i++){
brr=arr[i].split(',');
str +='<li onclick=" xiangqing('+brr[0]+')"> '+
' <div class="a-content"> ' +
' <img class="left" src=" '+brr[1]+' "> '+
' <h3 class="right"> '+
brr[3] +
' </h3> '+
' </div> '+
'<li>';
}
//然后把数据放入到html里面
$('.a-content').html(str);
}