马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
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[0];
- $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;
- */
- ?>
复制代码
内容就是不显示出来,找了很多网上,方法都用到了,我把文件都放在同一个目录下。求大神帮忙 |