HTML5+EaSyUi +php +mysql 仿问数据库显示不出来,求大神帮忙????
HTML5+EaSyUi +php +mysql 仿问数据库显示不出来,求大神帮忙????index.html 中的代码是这样的
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> JSEasy 表格边接数据库</title>
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/color.css">
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/demo/demo.css">
<script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.min.js"></script>
<script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
</head>
<body>
<div id="toolbar">
<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">添加客户</a>
<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">修改客户</a>
<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除</a>
</div>
<div id="dlg-buttons">
<a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">提交</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
</div>
<!--建立表格的表头-->
<table id="dg" title="客户预览" class="easyui-datagrid" url="get_users.php" style="width:700px;height:250px" toolbar="#toolbar" rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th field="firstname" width="50">姓名</th>
<th field="lastname" width="50">地址</th>
<th field="phone" width="50">联系方式</th>
<th field="email" width="50">Email</th>
</tr>
</thead>
</table>
<div id="dlg" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
<form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
<h3>新建用户</h3>
<div style="margin-bottom:10px">
<input name="firstname" class="easyui-textbox" required="true" label="姓名:" style="width:100%">
</div>
<div style="margin-bottom:10px">
<input name="lastname" class="easyui-textbox" required="true" label="地址::" style="width:100%">
</div>
<div style="margin-bottom:10px">
<input name="phone" class="easyui-textbox" required="true" label="联系方式:" style="width:100%">
</div>
<div style="margin-bottom:10px">
<input name="email" class="easyui-textbox" required="true" validType="email" label="Email:" style="width:100%">
</div>
</form>
</div>
<script>
var url;
// 新建用户
function newUser() {
$('#dlg').dialog('open').dialog('center').dialog('setTitle', '新建客户');
$('#fm').form('clear');
url = 'save_user.php';
}
//修改用户
function editUser() {
var row = $('#dg').datagrid('getSelected');
if (row) {
$('#dlg').dialog('open').dialog('center').dialog('setTitle', 'Edit User');
$('#fm').form('load', row);
url = 'update_user.php?id=' + row.id;
}
}
//保存存用户
function saveUser() {
$('#fm').form('submit', {
url: "save_user.php",
onSubmit: function() {
return $(this).form('validate');
},
success: function(result) {
var result = eval('(' + result + ')');
if (result.errorMsg) {
$.messager.show({
title: 'Error',
msg: result.errorMsg
});
} else {
$('#dlg').dialog('close'); // close the dialog
$('#dg').datagrid('reload'); // reload the user data
}
}
});
}
//删除用户
function destroyUser() {
var row = $('#dg').datagrid('getSelected');
if (row) {
$.messager.confirm('Confirm', 'Are you sure you want to destroy this user?', function(r) {
if (r) {
$.post('destroy_user.php', {
id: row.id
}, function(result) {
if (result.success) {
$('#dg').datagrid('reload'); // reload the user data
} else {
$.messager.show({ // show error message
title: 'Error',
msg: result.errorMsg
});
}
}, 'json');
}
});
}
}
</script>
</body>
</html>
PHP 代码是这样的,文件名是:get_users.php
<?php
/*
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset = ($page-1)*$rows;
*/
//include 'conn.php';
$servername = "127.0.0.1";
$username = "root";
$password = "12345678";
// 创建连接
$conn = new mysqli($servername,$username,$password);
// 验证连接
if (!$conn) {
die('连接失败!!!' . $conn->connect_error);
}
echo "连接成功<br>";
mysqli_query($conn , "set names utf8");
$tb_coon = mysqli_select_db($conn,'mydb');
$rs = mysqli_query($conn,"select * from users");
$result = array();
/*
$row = mysqli_fetch_row($rs);
$result["total"] = $row;
$rs = mysqli_query($conn,"select * from users limit $offset,$rows");
$items = array();
while($row = mysqli_fetch_object($rs)){
array_push($items, $row);
}
$result["rows"] = $items;
*/
while($row = mysqli_fetch_object($rs)){
array_push($result, $row);
}
echo json_encode($result);
/*
$rs->free();
$mysql->closedir;
*/
?>
内容就是不显示出来,找了很多网上,方法都用到了,我把文件都放在同一个目录下。求大神帮忙 查一下前端,看看后台数据是否能传过来 wp231957 发表于 2021-10-14 19:24
查一下前端,看看后台数据是否能传过来
怎么查?
黄翼 发表于 2021-10-15 09:12
怎么查?
这东西也好查也不好查 我不咋懂PHP也没你的数据库 所以基本帮不到你
宗旨就一点,打通前后台通道,确保前端数据后台能正确接到
确保后台数据前端能正确接到并渲染
这东西就得自己慢慢查别无它法 黄翼 发表于 2021-10-15 09:12
怎么查?
实在不行,可以把你的sql打包后的数据 给我发出来
页:
[1]