php查询mysql显示到表格中

DKCCCH 2015-06-11 04:07:13


像这个图片中的表格,是创建好的

然后通过按钮把mysql中的数据分别更新显示到总人数中,该怎样写,麻烦详细点

...全文
260 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
傲雪星枫 2015-06-11
  • 打赏
  • 举报
回复
client.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
  <title> test </title>
  <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
 </head>

 <body>
    <table>
      <tr>
        <td>类型</td>
        <td>总人数</td>
      </tr>
      <tr>
        <td>学生</td>
        <td id="student"></td>
      </tr>
      <tr>
        <td>老师</td>
        <td id="teacher"></td>
      </tr>
    </table>
    <input type="button" name="b1" value="显示" onclick="show()">
    <script type="text/javascript">
    function show(){
    $.post("server.php",{})
      .done(function(data){
        $('#student').html(data.student);
        $('#teacher').html(data.teacher);
      });
    }
    </script>
 </body>
</html>

server.php

<?php
$ret = array(
    'student' => 100,
    'teacher' => 200
);

header('content-type:application:json;charset=utf8');
echo json_encode($ret);
?>
mysql 部分你可以自己写出,然后放入$ret便可。
DKCCCH 2015-06-11
  • 打赏
  • 举报
回复
不用按钮了,直接打开就刷新
DKCCCH 2015-06-11
  • 打赏
  • 举报
回复
好吧,表示ajax好多还是看不懂,能否先来一个例子看看
果酱很好吃 2015-06-11
  • 打赏
  • 举报
回复
用ajax实现,找一个简单的ajax例子看看吧

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧