//header(‘Content-Type:text/json;charset=utf-8‘);
$con=mysqli_connect("数据库地址:端口","用户名","密码","数据库名");if (!$con)
{die("连接错误: " . mysqli_connect_error());
}else{echo "成功";
}$action = $_GET[‘action‘];switch ($action) {case ‘del_row‘:del_row();//删除
break;case ‘edit_row‘:edit_row();//查询
break;}functiondel_row(){global $con;$dataid = $_POST[‘dataid‘];$sql = "delete from `order` where `id`=‘".$dataid."‘";if (mysqli_query($con,$sql)) {echo ‘ok‘;
}else{echo ‘删除失败‘;
}
}functionedit_row(){global $con;$sql = "SELECT id, name, mobile FROM `user_address`";//sql查询语句
$result = $con->query($sql);//获得查询结果
if ($result->num_rows > 0) {//输出每行数据
while($row = $result->fetch_assoc()) {$results[] = $row;
}
}else{echo "0 results";
}echo json_encode($results);
}?>
前端代码
$.ajax({
type:"GET",
url:"./data.php?action=edit_row",
data:‘‘,
dataType:"json",
success:function(data){var len =data.length,
str= ‘‘, item;if(len>0) {for (var i = 0; i < len; i++) {
item=data[i];
str+= ‘
‘ +‘
‘ + item.id + ‘‘ +‘
‘ + item.name + ‘‘ +‘
‘ + item.mobile + ‘‘ +‘
‘ + item.city + ‘‘ +‘
‘ + item.country + ‘‘ +‘
‘ + item.detail + ‘‘ +‘
‘ + ‘ ‘+‘删除‘+‘‘ + ‘‘ +‘
‘;}
$(‘#order-table1‘).append(str);
}
}
});
php实现的mysql的简单查询删除
标签:address nec app blog apache for log type echo
本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉
本文系统来源:http://www.cnblogs.com/lqzweb/p/7101743.html