jqery查询数据库,动态获取数据库里面的参数

//查询数据库,动态获取产品的图片,型号等信息

 $(".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;
	}

?>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值