字符串的另一种写法:<<<AAAA; 后两个AA回车要求顶格 不然报错
例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php
$str = <<<AA
ffffff909090(0000));'''''''''""""
AA;
echo $str;
?>
</body>
</html>
图:
①House分七个页面 数据库为 test2 House 表 注意form:chuli的表可以与相关表合并为一个 分开较清晰
分别是
1,Hmain.php:主页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>编号</td>
<td>关键字</td>
<td>区域</td>
<td>使用面积</td>
<td>租金</td>
<td>租赁类型</td>
<td>房屋类型</td>
<td>操作</td>
</tr>
<?php
//造连接对象
$db=new mysqli("localhost","root","123","test2");
//判断连接是否成功
!mysqli_connect_error()or die("连接失败!");
//写sql语句
$sql="select * from House";
//执行sql语句
$result=$db->query($sql);
//处理查询的结果
$attr=$result->fetch_all();
for ($i=0; $i <count($attr) ; $i++) {
echo "<tr>";
for ($j=0; $j <count($attr[$i]); $j++) {
echo "<td>{$attr[$i][$j]}</td>";
}
echo "<td><a href='Hdelete.php?code={$attr[$i][0]}'>删除</a><a href='Hupdate.php?code={$attr[$i][0]}'>修改</a></td>";
echo "</tr>";
}
?>
</table>
<br/>
<a href="Hadd.php"><input type="button" value="添加数据"></a>
</body>
</html>
图:
2,Hadd.php:添加页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style>
.kong
{
margin:10px 0px 10px 0px;
vertical-align:
}
</style>
<body>
<form action="Haddchuli.php" method="post"> <div class="kong">
编       号
<input type="text" name="code"/>
</div> <div class="kong">
关  键 字
<input type="text" name="keyword"/>
</div>
<div class="kong">
区       域
<input type="text" name="quyu"/>
</div>
<div class="kong">
使用面积
<input type="text" name="mianji"/>
</div>
<div class="kong">
租       金
<input type="text" name="zujin">
</div>
<div class="kong">
租赁类型
<input type="text" name="zulei"/>
</div>
<div class="kong">
房屋类型
<input type="text" name="fanglei"/>
</div>
<div>
<input type="submit" value="确定"/>
<a href="Hmain.php">返回</a>
</div>
</form>
</body>
</html>
图:
3,Haddchuli.php:添加处理页面
<?php
$code=$_POST["code"];
$keyword=$_POST["keyword"];
$quyu=$_POST["quyu"];
$mianji=$_POST["mianji"];
$zujin=$_POST["zujin"];
$zulei=$_POST["zulei"];
$fanglei=$_POST["fanglei"];
//造连接对象
$db=new mysqli("localhost","root","123","test2");
//判断是否出错
!mysqli_connect_error() or die("连接失败");
//写sql语句
$sql="insert into House values('$code','$keyword','$quyu','$mianji','$zujin','$zulei','$fanglei')";
//执行语句
$result=$db->query($sql);
if ($result) {
header("location:Hadd.php");
}
else{
echo "执行失败!";
}
?>}
4,Hdelete.php:删除页面
<?php $code=$_GET["code"];
$db=new mysqli("localhost","root","123","test2");
!mysqli_connect_error() or die("连接有误!");
$sql="delete from House where id='$code'";
$result=$db->query($sql);
if ($result) {
header("location:Hmain.php");
}
else{
echo "删除失败!";
}
?>}
图:删除上图的第18个 主键删除后不会再次启用 而是以此向下排序
5,Hupdate.php:修改页面 使用面积和租金 数字填完之后有点奇怪?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php
$code=$_GET["code"];
$db=new mysqli("localhost","root","123","test2");
!mysqli_connect_error()or die("连接有误!");
$sqlu="select * from House where id='$code'";
$result=$db->query($sqlu);
$attu=$result->fetch_row(); ?>
<form action="Hupdatechuli.php" method="post"> <div>
编       号:
<input type="text" name="code" value="<?php echo $attu[0] ?>"/>
</div> <div>
关 键 字  :
<input type="text" name="keyword" value="<?php echo $attu[1] ?>"/>
</div>
<div>
区       域:
<input type="text" name="quyu" value="<?php echo $attu[2] ?>"/>
</div>
<div>
使用面积:
<input type="text" name="mianji" value="<?php echo $attu[3] ?>"/>
</div>
<div>
租       金:
<input type="text" name="zujin" value="<?php echo $attu[4] ?>"/>
</div>
<div>
租赁类型:
<input type="text" name="zulei" value="<?php echo $attu[5] ?>"/>
</div>
<div>
房屋类型:
<input type="text" name="fanglei" value="<?php echo $attu[6] ?>"/>
</div>
<div>
<input type="submit" value="确定"/>
<a href="Hmain.php">返回</a>
</div>
</form>
</body>
</html>
图:
6,Hupdatechuli.php:修改处理页面
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php $code=$_POST["code"];
$keyword=$_POST["keyword"];
$quyu=$_POST["quyu"];
$mianji=$_POST["mianji"];
$zujin=$_POST["zujin"];
$zulei=$_POST["zulei"];
$fanglei=$_POST["fanglei"];
//造连接对象
$db=new mysqli("localhost","root","123","test2");
//判断是否出错
!mysqli_connect_error() or die("连接失败");
//写sql语句
$sql="update House set KeyWord='$keyword',Area='$quyu',SquareMeter='$mianji',Rent='$zujin',RentType='$zulei',HouseType='$fanglei'where id='$code'";
//执行语句
$result=$db->query($sql);
if ($result) {
header("location:Hadd.php");
}
else{
echo "执行失败!";
}
?>
7,hhcheck.php:多条件联合查询页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php
@$qytj=$_POST["qy"];
@$zltj=$_POST["zl"];
@$fltj=$_POST["fl"];
@$key=$_POST["key"]; //造查询字符串
$st1=" 1=1";
$st2=" 1=1";
$st3=" 1=1";
$st4=" 1=1";
//判断第一个条件是否有值
if (count($qytj)>0) {
$ss=implode("','",$qytj);
$st1=" Area in ('$ss') ";
}
//依次判断第二三四个条件
if (count($zltj)>0) {
$zz=implode("','",$zltj);
$st2=" Renttype in ('$zz')";
}
if (count($fltj)>0) {
$ff=implode("','",$fltj);
$st3=" HouseType in ('$ff')";
}
if ($key!="") { $st4=" KeyWord like '%$key%'";
}
$sqltj=" where".$st1." and ".$st2." and ".$st3." and ".$st4; ?>
<form action="hhcheck.php" method="post">
<div>
<div>区域:
<input type="checkbox" id="qyall" name="qyall" onclick="CheckAll(this,'qy')">全选
</div>
<div>
<?php
//1.造连接对象
$db=new mysqli("localhost","root","123","test2");
//2.判断是否连接成功
!mysqli_connect_error()or die("连接失败");
$sqlqy="select distinct(Area) from House";
$result=$db->query($sqlqy);
$arrqy=$result->fetch_all();
for ($i=0; $i <count($arrqy); $i++) {
echo "<div style='display:inline'><input type='checkbox' name='qy[]' class='qy' value='{$arrqy[$i][0]}'>{$arrqy[$i][0]}</div> ";
}
?>
</div>
<br>
<div>租赁类型:
<input type="checkbox" id="zlall" name="zlall" onclick="CheckAll(this,'zl')">全选
</div>
<div>
<?php
//1.造连接对象
$db=new mysqli("localhost","root","123","test2");
//2.判断是否连接成功
!mysqli_connect_error()or die("连接失败");
$sqlzl="select distinct(Renttype) from House";
$result=$db->query($sqlzl);
$arrzl=$result->fetch_all();
for ($i=0; $i <count($arrzl); $i++) {
echo "<div style='display:inline'><input type='checkbox' name='zl[]' class='zl'value='{$arrzl[$i][0]}'>{$arrzl[$i][0]}</div> ";
}
?>
</div>
<br>
<div>房屋类型:
<input type="checkbox" id="flall" name="fl[]" onclick="CheckAll(this,'fl')">全选
</div>
<div>
<?php
//1.造连接对象
$db=new mysqli("localhost","root","123","test2");
//2.判断是否连接成功
!mysqli_connect_error()or die("连接失败");
$sqlfl="select distinct(HouseType) from House";
$result=$db->query($sqlfl);
$arrfl=$result->fetch_all();
for ($i=0; $i <count($arrfl); $i++) {
echo "<div style='display:inline'><input type='checkbox' name='fl[]' class='fl' value='{$arrfl[$i][0]}'>{$arrfl[$i][0]}</div> ";
}
?>
</div>
<br>
<div>关键字:
<input type="text" name="key">
<input type="submit" value="搜索">
</div>
</div>
</form>
<table border="1" width=100% cellpadding="0" cellspacing="0">
<tr>
<td>关键字</td>
<td>区域</td>
<td>面积</td>
<td>租金</td>
<td>租赁类型</td>
<td>房屋类型</td>
</tr>
<?php
//1.造连接对象
$db=new mysqli("localhost","root","123","test2");
//2.判断是否连接成功
!mysqli_connect_error()or die("连接失败");
$sql="select * from House ".$sqltj;
$result=$db->query($sql);
$arral=$result->fetch_all();
for($i=0; $i<count($arral); $i++){
echo "<tr>
<td>{$arral[$i][1]}</td>
<td>{$arral[$i][2]}</td>
<td>{$arral[$i][3]}</td>
<td>{$arral[$i][4]}</td>
<td>{$arral[$i][5]}</td>
<td>{$arral[$i][6]}</td>
</tr>";
} ?>
</table>
</body>
<script type="text/javascript">
function CheckAll(checked,cname)
{ var all=document.getElementsByClassName(cname);
for (var i = 0; i < all.length; i++) {
all[i].checked=checked.checked;
}
}
</script>
</html>
图一:
图二:图一条件查出的结果
图三: 全选中时 下面选项也选中 但有个缺陷 部分不选时 全选还是存在 接下来解决
②加一个页面 checkbox 中选项任意一个不选 全选自动取消
YiGeBuZhongQuanBuZhong.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="checkbox" id="quan" name="qx" onclick="CheckAll(this,'list')">全选
<div>
<input type="checkbox" class="list" onclick="Checkpa(this)">
<input type="checkbox" class="list" onclick="Checkpa(this)">
<input type="checkbox" class="list" onclick="Checkpa(this)">
<input type="checkbox" class="list" onclick="Checkpa(this)">
<input type="checkbox" class="list" onclick="Checkpa(this)">
<input type="checkbox" class="list" onclick="Checkpa(this)">
</div>
</body>
<script>
function CheckAll(ck,list)
{ //找到全选按钮的选中状态
var zt=ck.checked;
//找到所有控制的checkbox
var all=document.getElementsByClassName(list);
//控制所有的checkbox状态和全选的状态一致
for (var i = 0; i < all.length; i++) {
all[i].checked=zt;
}
}
function Checkpa(pa)
{
if(!pa.checked)
{
document.getElementById("quan").checked=
false;
}
}
</script>
</html>