//查询数据库,动态获取产品的图片,型号等信息
$(".oli").each(function(index){
let n=index+1;
//console.log(n);
$.post("index.php",{id:n},function(res,status){
}).then(function(res){
var str = res;
//将返回的字符串进行分割
var a = str.split(",");
$(".particulars"+n).text(a[0]);
$(".particulars"+n).text(a[1]);
$(".oli"+n).attr("src",a[2]);
},function(res){
});
})
index.php代码
<?php
header("Content-type:text/html;charset=utf-8");
//1.创建连接对象
$conn = mysql_connect("localhost","root","root");
$id=$_POST["id"];
mysql_select_db("longines");
$result = mysql_query("select * from information_watch where watchNum='$id'",$conn);
if(mysql_num_rows($result) ==1){
//前后端分离
// mysql_fetch_assoc()方法将表格以josn集合形式返回
while($row = mysql_fetch_assoc($result)){
//如需返回多个,用点连接
//此处可以用符号连接,返回的字符串中就有字符串,可以使用split()进行分割
echo $row["watchSetName"].",".$row["watchId"].",".$row["watchImg"];
}
}else if(mysql_num_rows($result) ==0){
echo 0;
}
?>