练习题投票和租房子

Posted 小美好。

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了练习题投票和租房子相关的知识,希望对你有一定的参考价值。

一:投票,连个页面都引用了DBDA封装类

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*{
    margin:0px auto;
    padding:0px;
    }
.title
{
    height:50px;
    margin:20px 0px 0px 20px;
}
.list
{
    width:300px;
    height:200px;
    margin-left:20px;
}
.xx
{
    width:300px;
    height:30px;
}
.jieguo
{
    width:300px;
    height:200px;
    margin-left:20px;
}
.xxnr
{
    width:300px;
    height:30px;
}
</style>
</head>

<body>
    <form action="ChuLi.php" method="post">
        
    <?php
        include("DBDA.php");
        $db = new DBDA();
        
        $sql = "select * from DiaoYanTiMu";
        
        $result = $db->Query($sql);
        
        //题目标题
        echo "<div class=‘title‘>{$result[0][1]}</div>";
        
        $code = $result[0][0];
        
        $sqlx = "select * from DiaoYanXuanXiang where TiMuDaiHao = {$code}";
        $resultx = $db->Query($sqlx);
        
        $xian = "";
        if(@$_GET["bs"]==1)
        {
            $xian = "display:none";
        }
        else
        {
            $xian="display:block";
        }
        
        //题目选项的DIV
        echo "<div class=‘list‘ style=‘{$xian}‘>";
        
        for($i=0;$i<count($resultx);$i++)
        {
            echo "<div class=‘xx‘>";
            echo "<input type=‘checkbox‘ value=‘{$resultx[$i][0]}‘ name=‘opt[]‘ />";
            echo "<span>{$resultx[$i][1]}</span>";
            echo "</div>";
        }

        echo "</div>";
        
        //下面是投票结果的DIV
        $xianshi = "";
        if(@$_GET["bs"]==1)
        {
            $xianshi = "display:block";
        }
        else
        {
            $xianshi="display:none";
        }
        echo "<div class=‘jieguo‘ style=‘{$xianshi}‘>";
        
        //求总人数
        $sqlcount = "select sum(Numbers) from DiaoYanXuanXiang";
        $attrcount = $db->Query($sqlcount);
        
        for($j=0;$j<count($resultx);$j++)
        {
            $rs = $resultx[$j][2];
            if($attrcount[0][0]==0)
            {
                $bfb = 0;
            }
            else
            {
                $bfb = ($rs/$attrcount[0][0])*100;
            }
            
            echo "<div class=‘xxnr‘>";
        
            echo "<span style=‘float:left‘>{$resultx[$j][1]}</span>";
            echo "<div style=‘float:left;margin:10px 0px 0px 10px;width:100px; height:4px; border:1px solid #000‘>
            <div style=‘width:{$bfb}%; height:4px;margin-left:0px; background-color:#666‘></div>
            </div>";
            echo "<span style=‘float:left; margin-left:10px‘>{$resultx[$j][2]}</span>";
            
            echo "</div>";
        }
        

        
        
        echo "</div>";
        
    ?>
        
    <div style="margin-left:20px; width:200px">
        <input id="tj" type="submit" style="float:left;<?php echo $xian; ?>;margin:0px 0px 0px 10px" value="提交" />
        <input id="fh" type="button" style="float:left;<?php echo $xianshi;?>;margin:0px 0px 0px 10px" onclick="ShowTP()" value="返回" />
        <input type="button" style="float:left;display:block;margin:0px 0px 0px 10px" onclick="ShowJieGuo()" value="显示结果" />
    </div>
    </form>
</body>

<script type="text/javascript">
function ShowJieGuo()
{
    var list = document.getElementsByClassName("list");
    var jieguo = document.getElementsByClassName("jieguo");
    var tj = document.getElementById("tj");
    var fh = document.getElementById("fh");
    
    fh.style.display="block";
    tj.style.display="none";
    list[0].style.display="none";
    jieguo[0].style.display ="block";
}
function ShowTP()
{
    var list = document.getElementsByClassName("list");
    var jieguo = document.getElementsByClassName("jieguo");
    var tj = document.getElementById("tj");
    var fh = document.getElementById("fh");
    
    fh.style.display="none";
    tj.style.display="block";
    list[0].style.display="block";
    jieguo[0].style.display ="none";
}
</script>
</html>

投票过来的处理页面

<?php

include("DBDA.php");
$db = new DBDA();

$attr = $_POST["opt"];



for($i=0;$i<count($attr);$i++)
{    
    $sql = "update DiaoYanXuanXiang set Numbers = Numbers+1 where Ids = {$attr[$i]}";
    
    $db->Query($sql,0);
}

header("location:Test.php?bs=1");

二:租房子

主页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
    a{
        text-decoration:none;
    }
    a:link,a:visited{
            color:#00F;
    }
    table{
        text-align:center;    
    }
    span{
        color:#00F;
        cursor:pointer;    
    }
</style>
</head>

<body>
<table width="100%" cellpadding="0" cellspacing="0" border="1">
    <tr><td>操作</td><td>关键字</td><td>区域</td><td>使用面积</td><td>租金</td><td>租赁类型</td><td>房屋类型</td></tr>
    <?php
        //连接数据库,取出数据,并在表格中显示
        include("DBDA.php");
        $db=new DBDA();
        $sql="select * from house order by keyword";
        $result=$db->Query($sql,1,"housedb");
        //var_dump($result);
        $strconfirm="\"确认删除?\"";
        for($i=0;$i<count($result);$i++){
            
            echo "<tr>
                    <td>
                        <a href=‘AddInfo.php?bj=2&id={$result[$i][0]}‘>编辑</a>
                        <a href=‘AddInfo.php?bj=3&id={$result[$i][0]}‘
                            onclick=‘javascript:if(confirm({$strconfirm})){return ture}else{return false}‘
                        >删除</a>
                    </td>
                    <td>{$result[$i][1]}</td>
                    <td>{$result[$i][2]}</td>
                    <td>{$result[$i][3]}</td>
                    <td>{$result[$i][4]}</td>
                    <td>{$result[$i][5]}</td>
                    <td>{$result[$i][6]}</td>    
                  </tr>";
        }
    ?>
</table>
<a href="AddInfo.php?bj=1"><input type="button" value="添加数据"/></a>
<a href="search.php"><input type="button" value="查询"/></a>
<script>
    /*function Confirm(){
        var f=document.getElementsByClassName("tz");
        for(var i=0;i<f.length;i++){
                
        }
        var bool=confirm("你确定删除?");
        alert(bool);
        if(bool){
            window.location.href="";    
        };
    }*/
</script>
</body>
</html>

处理页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
    include("DBDA.php");
    $bj=$_GET["bj"];
    $db=new DBDA();
    //$bj=1;
    if($bj==1){
        $arradd=$_POST["sja"];
        //var_dump($arradd);
        $str="‘{$arradd[0]}‘,‘{$arradd[1]}‘,{$arradd[2]},{$arradd[3]},‘{$arradd[4]}‘,‘{$arradd[5]}‘";
        //echo $str."<br/>";
        $sql="INSERT INTO house(keyWord,area,squaremeter,rent,renttype,housetype) VALUES ({$str})";
        //echo $sql;
        $bool=$db->Query($sql,0,"housedb");
        if($bool){
            header("location:HouseInfo.php");    
        }else{
            header("location:AddInfo.php?bj=1;");    
        }
        
    }else if($bj==2){
            $arrupdate=$_POST["sja"];
            $id=$_GET["id"];
            $sql="delete from house where id={$id}";
            $bool=$db->Query($sql,0,"housedb");
            $stru="‘{$arrupdate[0]}‘,‘{$arrupdate[1]}‘,{$arrupdate[2]},{$arrupdate[3]},‘{$arrupdate[4]}‘,‘{$arrupdate[5]}‘";
            $sqlu="INSERT INTO house(keyWord,area,squaremeter,rent,renttype,housetype) VALUES ({$stru})";    
            $db->Query($sqlu,0,"housedb");
            header("location:HouseInfo.php");
    }
?>
</body>
</html>

添加,删除,修改

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
    a{
        text-decoration:none;
    }
    .text{
        display:inline-block;
        width:100px;
        text-align:center;    
    }
</style>
</head>
<body>
    <?php
        $bj=$_GET["bj"];
        //$bj=1;
        include("DBDA.php");
        $db=new DBDA();
        //echo $bj;
        if($bj==1){
            //添加数据
            echo "
                    
                  <form action=‘chuli.php?bj=1‘ method=‘post‘>    
                      <div class=‘text‘>关键字:</div><input type=‘text‘ name=‘sja[]‘/><br/>
                      <div class=‘text‘>区域:</div><input type=‘text‘ name=‘sja[]‘/><br/>
                      <div class=‘text‘>使用面积:</div><input type=‘text‘ name=‘sja[]‘/><br/>
                      <div class=‘text‘>租金:</div><input type=‘text‘ name=‘sja[]‘/><br/>
                      <div class=‘text‘>租赁类型:</div><input type=‘text‘ name=‘sja[]‘/><br/>
                      <div class=‘text‘>房屋类型:</div><input type=‘text‘ name=‘sja[]‘/><br/>
                      <input type=‘submit‘ value=‘插入‘/>
                      <a href=‘HouseInfo.php‘><input type=‘button‘ value=‘取消‘/></a>
                  <form>
                  ";
        }else if($bj==2){
            //修改数据
            $idu=$_GET["id"];
            $sqlu="select * from house where id={$idu}";
            $arrUpdate=$db->Query($sqlu,1,"housedb");
            echo "
                  <form action=‘chuli.php?bj=2&id={$arrUpdate[0][0]}‘ method=‘post‘>    
                      <div class=‘text‘>关键字</div><input type=‘text‘ name=‘sja[]‘ value=‘{$arrUpdate[0][1]}‘/><br/>
                      <div class=‘text‘>区域</div><input type=‘text‘ name=‘sja[]‘ value=‘{$arrUpdate[0][2]}‘/><br/>
                      <div class=‘text‘>使用面积</div><input type=‘text‘ name=‘sja[]‘ value=‘{$arrUpdate[0][3]}‘/><br/>
                      <div class=‘text‘>租金</div><input type=‘text‘ name=‘sja[]‘ value=‘{$arrUpdate[0][4]}‘/><br/>
                      <div class=‘text‘>租赁类型</div><input type=‘text‘ name=‘sja[]‘ value=‘{$arrUpdate[0][5]}‘/><br/>
                      <div class=‘text‘>房屋类型</div><input type=‘text‘ name=‘sja[]‘ value=‘{$arrUpdate[0][6]}‘/><br/>
                      <input type=‘submit‘ value=‘更新‘/>
                      <a href=‘HouseInfo.php‘><input type=‘button‘ value=‘取消‘/></a>
                  <form>
                  ";
        }else if($bj==3){
            //删除数据
            $id=$_GET["id"];
            $sql="delete from house where id={$id}";
            $bool=$db->Query($sql,0,"housedb");
                header("location:HouseInfo.php");

            
        }
    
    
    ?>

</body>
</html>

 

以上是关于练习题投票和租房子的主要内容,如果未能解决你的问题,请参考以下文章

创建广告时出现代码 200 和子代码 1487194 的 Facebook 错误背后的原因是啥?

PHP 练习租房

错误 - EXC_BREAKPOINT(代码=1,子代码=0x100308448)

代码=exc_i386_invop 子代码=0x0 笔尖 xcode7.2

iContact卷曲子代码

线程 1:EXC_BAD_INSTRUCTION(代码=EXC_1386_INVOP,子代码=0x0)