這篇文章介紹的內容是關於ajax php mysql 讀取資料庫的簡單範例,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下
1.建立資料庫##
create database ajaxdemo default charset utf8;
use ajaxdemo;
建立表格並插入資料
CREATE TABLE `ajaxtest` ( `userid` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户id', `username` varchar(50) NOT NULL COMMENT '用户名', `userpass` varchar(50) NOT NULL COMMENT '密码', `userage` int(11) NOT NULL COMMENT '年龄', `usersex` varchar(1) NOT NULL COMMENT '性别', PRIMARY KEY (`userid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `ajaxtest` VALUES ('1', '李四', 'lisi', '15', '男'); INSERT INTO `ajaxtest` VALUES ('2', '张三', 'lisi', '20', '女'); INSERT INTO `ajaxtest` VALUES ('3', '王五', 'lisi', '25', '男'); INSERT INTO `ajaxtest` VALUES ('4', '韩梅梅', 'lisi', '25', '男'); INSERT INTO `ajaxtest` VALUES ('5', '张莉', 'lisi', '25', '女');
<html> <head> <meta charset="utf-8"/> <title>ajax实例</title> <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> </head> <body style="height: 800px;"> <p class="container"> <p class="panel panel-default" style="margin-top: 100px;text-align: center;"> <p class="panel-heading"> Ajax实例 </p> <p class="panel-body"> <form class="navbar-form navbar-center" role="search" name="myform"> <p class="form-group"> <label> 年龄:<input type="number" class="form-control" placeholder="Age" name="userage" id='userage'/> </label> </p> <select class="form-control" id="usersex" name="usersex"> <option value="男">男</option> <option value="女">女</option> </select> <button type="button" class="btn btn-default" onclick='ajaxFunction()'>提交</button> </form> <table class="table table-condensed table-bordered" id="ajaxp"></table> <p>SQL语句:<pre id="sql">