标签:box alt java 不为 二维数组 form php move 字符串
租房子练习题:重要颜色
1.模仿get传值到处理php页面:<a href=‘shanchu.php?c={$v[0]}‘ onclick=\"return confirm(‘确定删除吗?‘)\">删除</a>
2.删除页面显示确定删除提示框:<a href=‘shanchu.php?c={$v[0]}‘ onclick=\"return confirm(‘确定删除吗?‘)\">删除</a>
主页面:
<body> <table border="1" cellpadding="0" cellspacing="0" width="90%"> <tr> <th></th> <th></th> <th>关键字</th> <th>区域</th> <th>使用面积</th> <th>租金</th> <th>租赁类型</th> <th>房屋类型</th> </tr> <?php include("../fzl/czy.class.php"); $db = new czy(); $sql = "select * from house"; $attr = $db->Query($sql); foreach($attr as $v) { echo "<tr> <td><a href=‘gai.php?c={$v[0]}‘ \">编辑</a></<td> //c={$v[0]}是把主键值赋给c 模仿get传值 点哪条数据就通过主键值把数据通过get方式到修改页面 <td><a href=‘shanchu.php?c={$v[0]}‘ onclick=\"return confirm(‘确定删除吗?‘)\">删除</a></<td> <td>{$v[1]}</td> <td>{$v[2]}</td> <td>{$v[3]}</td> <td>{$v[4]}</td> <td>{$v[5]}</td> <td>{$v[6]}</td> </tr>"; } ?> </table> <a href="add.php"><input type="submit" name="tj" value="添加新数据"/></a> <a href="ss.php"><input type="button" value="搜索" /></a> </body>
添加数据主页面:点取消时 href="主页面.php" 点添加时 action="主页面处理页面.php"
<body> <?php include("../fzl/czy.class.php"); $db = new czy(); $sql = "select * from house"; $attr = $db->Query($sql); ?> <form action="azucl.php" method="post"> <div>关键字<input type="text" name="guanjianzi" /></div> <div>区域<input type="text" name="area" /></div> <div>使用面积<input type="text" name="areaa" /></div> <div>租金<input type="text" name="money" /></div> <div>租赁类型<input type="text" name="leixing" /></div> <div>房屋类型<input type="text" name="house" /></div> <input type="submit" value="添加" /><a href="azu.php"><input type="button" value="取消" /></a> </form> </body>
添加数据主页面处理页面:href:"主页面.php"
<?php include("../fzl/czy.class.php"); $db = new czy(); $guanjianzi = $_POST["guanjianzi"]; $area = $_POST["area"]; $areaa = $_POST["areaa"]; $money = $_POST["money"]; $leixing = $_POST["leixing"]; $house = $_POST["house"]; if($house != "" && $guanjianzi != "" && $area != "" && $areaa != "" && $money != "" && $leixing != "" ) { $sql = "insert into house values(‘‘,‘{$guanjianzi}‘,‘{$area}‘,{$areaa},{$money},‘{$leixing}‘,‘{$house}‘) ;"; $b = $db->Query($sql,0); if($b) { header("location:azu.php"); } else { echo "添加失败"; } } else { echo "输入的内容不能为空"; } ?>
修改数据主页面:确认修改按钮 action="修改处理页面.php" 点取消时 href="主页面.php"
把数据放在文本框<text>里面:<input type="hidden" value="<?php echo $arr[0] ?>" name="haoma" />
<body> <?php $haoma = $_GET["c"]; include("../fzl/czy.class.php"); $db = new czy(); $sql =" select * from house where ids = ‘$haoma‘"; $attr = $db->Query($sql); $arr = $attr[0];//把二维数组$attr 变为一维数组$arr ?> <form action="gaichuli.php" method="post"> <div><input type="hidden" value="<?php echo $arr[0] ?>" name="haoma" /></div> <div>关键字<input type="text" value="<?php echo $arr[1] ?>" name="guanjianzi" /></div> <div>区域<input type="text" value="<?php echo $arr[2] ?>" name="area" /></div> <div>使用面积<input type="text" value="<?php echo $arr[3] ?>" name="areaa" /></div> <div>租金<input type="text" value="<?php echo $arr[4] ?>" name="money" /></div> <div>租赁类型<input type="text" value="<?php echo $arr[5] ?>" name="leixing" /></div> <div>房屋类型<input type="text" value="<?php echo $arr[6] ?>" name="house" /></div> <input type="submit" value="确认修改" /> <a href="azu.php"><input type="button" value="返回" /></a> </form> </body>
修改处理页面: header("location:主页面.php");
<?php include("../fzl/czy.class.php"); $db = new czy(); $haoma = $_POST["haoma"]; $guanjianzi = $_POST["guanjianzi"]; $area = $_POST["area"]; $areaa = $_POST["areaa"]; $money = $_POST["money"]; $leixing = $_POST["leixing"]; $house = $_POST["house"]; if($house != "" && $guanjianzi != "" && $area != "" && $areaa != "" && $money != "" && $leixing != "" ) { $sql ="update house set keyword=‘{$guanjianzi}‘,area=‘{$area}‘,squarmeter={$areaa},rent={$money},renttype= ‘{$leixing}‘,housetype= ‘{$house}‘ where ids=‘{$haoma}‘ "; $t = $db->Query($sql,0); if($t) { header("location:azu.php"); } else { echo "修改失败<a href=‘azu.php‘>返回主页面</a>"; } } else { echo "输入的内容不能为空"; } ?>
删除处理页面:header("location:主页面.php");
<?php $haoma = $_GET["c"]; include("../fzl/czy.class.php"); $db = new czy(); $sql = (" delete from house where ids = ‘{$haoma}‘"); $db->Query($sql,0); header("location:azu.php"); ?>
搜索页面/包括修改处理:
1.多条件查询
2.去重查询
3.关键字查询变色
<style type="text/css"> .a{ float:left} .b{ float:left} .c{ float:left} #bbb{ margin-top:10px} </style> </head> <body> <form action="ss.php" method="post"> <?php include("../fzl/czy.class.php"); $db = new czy(); $sql = "select distinct area from house"; $attr = $db->Query($sql); echo "<div>区域:<input type=‘checkbox‘ onclick=‘show(this)‘ />全选</div>"; foreach ($attr as $v) { echo "<div class=‘a‘><input class=‘o‘ value=‘{$v[0]}‘ name=‘sz1[]‘ type=‘checkbox‘ />{$v[0]}</div>"; //多条件查询 } echo "<br/>"; echo "<div>租赁类型:<input type=‘checkbox‘ onclick=‘show1(this)‘ />全选</div>"; //area checkbox ?> <?php $sql1 = "select distinct renttype from house"; $attr1 = $db->Query($sql1); foreach ($attr1 as $v) { echo "<div class=‘b‘><input name=‘sz2[]‘ value=‘{$v[0]}‘ class=‘o2‘ type=‘checkbox‘ />{$v[0]}</div>"; //多条件查询 } echo "<br/>"; //renttype checkbox ?> <?php $sql2 = "select distinct housetype from house"; //去重 $attr2 = $db->Query($sql2); echo "<div>房屋类型:<input type=‘checkbox‘ onclick=‘show2(this)‘ />全选</div>"; foreach ($attr2 as $v) { echo "<div class=‘c‘><input name=‘sz3[]‘ value=‘{$v[0]}‘ class=‘o3‘ type=‘checkbox‘ />{$v[0]}</div>"; //多条件查询 } echo "<br/>"; //housetype checkbox ?> <div>关键字:<input type="text" name="ss" /> <input type="submit" value="搜索" /> <a href="azu.php"><input type="button" value="返回" /></a> </div> <div id="bbb"><table border="1" bordercolor="#f5f5f5" cellpadding="0" cellspacing="0" width="35%"> <tr> <th>关键字</th> <th>区域</th> <th>使用面积</th> <th>租金</th> <th>租赁类型</th> <th>房屋类型</th> </tr> <?php $ssm = ""; //关键字查询变色 @$ss = $_POST["ss"]; //多条件查询 $tj =" 1=1 "; $tj1 = " 1=1 "; $tj2 = " 1=1 "; $tj3 = " 1=1 "; if($ss!="") { $ssm = $_POST["ss"]; //关键字查询变色 输入的关键字不为空或者空字符串 $tj =" keyword like ‘%{$ss}%‘"; } //以上为$tj:关键字keyword查询 $asz1 =array(); if(@$_POST["sz1"] != "") { $asz1 = $_POST["sz1"]; $str1 = implode("‘,‘",$asz1); $tj1 = " area in (‘{$str1}‘) "; } //以上为$tj1:area查询 $asz2 =array(); if(@$_POST["sz2"] != "") { $asz2 = $_POST["sz2"]; $str2 = implode("‘,‘",$asz2); $tj2 = " renttype in (‘{$str2}‘) "; } //以上为$tj2:renttype查询 $asz3 =array(); if(@$_POST["sz3"] != "") { $asz3 = $_POST["sz3"]; $str3 = implode("‘,‘",$asz3); $tj3 = " housetype in (‘{$str3}‘) "; } //以上为$tj3:housetype查询 $sqs = "select * from house where ".$tj." and ".$tj1." and ".$tj2." and ".$tj3; $arr = $db->Query($sqs); foreach($arr as $v) { $aaname = str_replace($ssm,"<span style=‘color:blue‘>{$ssm}</span>",$v[1]); //关键字查询变色 echo "<tr> <td>{$aaname}</td> //关键字查询变色 <td>{$v[2]}</td> <td>{$v[3]}</td> <td>{$v[4]}</td> <td>{$v[5]}</td> <td>{$v[6]}</td> </tr>"; } ?> </table></div> </form> </body> <script type="text/javascript"> function show(a) //点击全选复选款按钮,通过循环把旗下的所有复选框按钮都选中‘checked‘=‘checked‘,点击取消时,旗下所有复选框按钮取消‘checked‘ { var b =document.getElementsByClassName("o"); for(var i=0; i<b.length;i++) { if(a.checked) { b[i].setAttribute("checked","checked"); } else { b[i].removeAttribute("checked"); } } } function show1(a) { var b =document.getElementsByClassName("o2"); for(var i=0; i<b.length;i++) { if(a.checked) { b[i].setAttribute("checked","checked"); } else { b[i].removeAttribute("checked"); } } } function show2(a) { var b =document.getElementsByClassName("o3"); for(var i=0; i<b.length;i++) { if(a.checked) { b[i].setAttribute("checked","checked"); } else { b[i].removeAttribute("checked"); } } } </script>
标签:box alt java 不为 二维数组 form php move 字符串
原文地址:http://www.cnblogs.com/cuizhenyu/p/6034432.html