主要功能是从postgreSql查询数据,并检索,由于自己刚开始接触,所以难点在于多条数据同时筛选并分页显示出来,写下自己的代码与大家共享。


<html>
<head>
<script type="text/javascript">

/**
* 分页函数
* pno--页数
* psize--每页显示记录数
* 分页部分是从真实数据行开始,因而存在加减某个常数,以确定真正的记录数
* 纯js分页实质是数据行全部加载,通过是否显示属性完成分页功能
**/

function goPage(pno,psize){
var itable = document.getElementById("idData");
var num = itable.rows.length;//表格所有行数(所有记录数)
console.log(num);
var totalPage = 0;//总页数
var pageSize = psize;//每页显示行数
//总共分几页
if(num/pageSize > parseInt(num/pageSize)){
totalPage=parseInt(num/pageSize)+1;
}else{
totalPage=parseInt(num/pageSize);
}
var currentPage = pno;//当前页数
var startRow = (currentPage - 1) * pageSize+1;//开始显示的行 31
var endRow = currentPage * pageSize;//结束显示的行 40
endRow = (endRow > num)? num : endRow; 40
console.log(endRow);
//遍历显示数据实现分页
for(var i=1;i<(num+1);i++){
var irow = itable.rows[i-1];
if(i>=startRow && i<=endRow){
irow.style.display = "block";
}else{
irow.style.display = "none";
}
}
var pageEnd = document.getElementById("pageEnd");
var tempStr = "共"+num+"条记录 分"+totalPage+"页 当前第"+currentPage+"页";
if(currentPage>1){
tempStr += "<a href=\"#\" onClick=\"goPage("+(1)+","+psize+")\">首页</a>";
tempStr += "<a href=\"#\" onClick=\"goPage("+(currentPage-1)+","+psize+")\"><上一页</a>"
}else{
tempStr += "首页";
tempStr += "<上一页";
}

if(currentPage<totalPage){
tempStr += "<a href=\"#\" onClick=\"goPage("+(currentPage+1)+","+psize+")\">下一页></a>";
tempStr += "<a href=\"#\" onClick=\"goPage("+(totalPage)+","+psize+")\">尾页</a>";
}else{
tempStr += "下一页>";
tempStr += "尾页";
}

document.getElementById("barcon").innerHTML = tempStr;

}
</script>
<style type="text/css">
table
{
text-align:center;
width:1000px;
}

th
{
width:100px;
}

input
{
width:100px;
}

td
{
width:100px;
}

</style>
</head>

<body onLoad="goPage(1,10);">
<form method="post" action="browes.php">
<table border="1">
<tr>
<th><h2>个人概况一览</h2></th>
</tr>
<tr>
<table border="1" >
<tr>
<td>姓:</td>
<td><input type="text" name="surname"> </td>
<td>名:</td>
<td><input type="text" name="name"> </td>

<td>手机:</td>
<td><input type="text" name="phone"> </td>

<td>性别:</td>
<td><select name="sex" id="select_k1" class="xla_k">
<option value=""> </option>
<option value="male"></option>
<option value="female"></option>
</select>
</td>

<td>学校:</td>
<td><input type="text" name="school"> </td>
</tr>

</table>
</tr>
<tr>
<td><input type="submit" name="submit" value="提交"> </td>
<td><input name=reset type=reset value=重置></td>
</tr>
</table>
</form>
</body>
<body>
<table id="idData" border="1" >
<tr>
<th>照片</th>
<th>姓名</th>
<th>性别</th>
<th>生日</th>
<th>邮箱</th>
<th>电话</th>
<th>学校</th>
<th>技能</th>
<th>选项</th>
</tr>
<?php
include "../head.php";
$s = $_POST["surname"];
$a = $_POST["name"];
$b = $_POST["phone"];
$c = $_POST["sex"];
$d = $_POST["school"];
/*
下面这段代码是PostgreSQL数据库多条数据检索编写数据库的通用方法
*/

$field = "where 1 = 1 ";
if($a){
//magic_quotes_gpc=on,addslashes not used.
$name = str_replace('\'', "''", $a);
$field.= "and (name like '%".$name."%') ";
}
if(($s)!=NULL){
$surname = str_replace('\'', "''", $s);
$field.= "and (surname like '%".$surname."%') ";
}
if(($c)!=NULL){
$field.= "and (sex = '".$c."') ";
}
if(($d)!=NULL){
$school = str_replace('\'', "''", $d);
$field.= "and (school like '%".$school."%') ";
}
if(($b)!=NULL){
$tel = str_replace('\'', "''", $b);
$field.= "and (phone = '".$tel."') ";
}

$sql = "select * from worker ".$field;
/*
上面这段代码是PostgreSQL数据库多条数据检索编写数据库的通用方法
*/

$ret = pg_query($db, $sql);
while($row=pg_fetch_row($ret)){
?>

<tr>
<td><?php echo $row[9];?></td>
<td><?php echo $row[1].$row[2];?></td>
<td><?php echo $row[3];?></td>
<td><?php echo $row[4];?></td>
<td><?php echo $row[5];?></td>
<td><?php echo $row[6];?></td>
<td><?php echo $row[7];?></td>
<td><?php echo $row[8];?></td>
<td><button><a href = "<?php echo 'change.php?id='.$row[0] ?>">change</button>
<button><a href = "<?php echo 'delete.php?id='.$row[0] ?>">delete</button></td>
</tr>
<?php } ?>
</table>
<table >
<div id="barcon" name="barcon"></div>
</table>
</body>
</html>

更多相关文章

  1. 五十行javascript代码实现简单的双向数据绑定
  2. 使用php Ajax在数据库中插入动态数据
  3. 如何使用客户端Javascript数组并通过节点发布。将js API插入Mong
  4. 如果外部应用程序更改了持久模型(服务器数据库),AngularJS可以自
  5. 如何在rails中使用ajax将数据从控制器传递到视图
  6. Javascript来自数据库的图像上的图像映射
  7. python数据类型二(列表和元组)
  8. 将敏感数据存储在数据库中,建议
  9. sklearn进行数据预处理-归一化/标准化/正则化

随机推荐

  1. Android 6.0及运行时权限处理
  2. [置顶] Android 各类功能效果源代码集合
  3. Android设置android:clipChildren达到的
  4. android的大好时光结束进行时
  5. 王家林的81门一站式云计算分布式大数据&
  6. Android串口Serial服务解析
  7. Android技术专家 高焕堂 推荐这本书
  8. Android音乐播放器系列讲解之一
  9. Android的ps命令介绍和技巧
  10. Android:关于声明文件中android:process