PHP,HTML和CSS的页面布局问题

时间:2011-02-01 08:02:25

标签: php html css formatting

出于某种原因,我的CSS没有将我的div标签格式化为页面上的正确位置。它适用于我所有的其他页面,但是这个页面中的PHP比正常情况要多得多,我想知道这是不是问题。 页

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
    require("protect/serverInfo.php");
    $myusername=$_POST[Email]; 
    $mypassword=$_POST[Password];
    $result = mysql_query("SELECT * FROM Customers WHERE Email='$myusername' AND Password=$mypassword");
    $count=mysql_num_rows($result);
    if($count==1){
        while($row = mysql_fetch_array($result)){
        ?>
        <div class="wrapper">
            <div class="customerHead">';
                <h1>  
                    <?php echo $row['Customer'] ?> 
                </h1>
            </div>
            <div class="customerInfoMain">
                 Company: <?php echo $row['Company'] ?><br />
                  State: <?php echo $row['State'] ?>
            </div>  
            <div class="customerCards">';
                 <a href ="something/<?php echo $row['imagePathFront'] ?>" target="_blank"><img src="<?php echo $row['imagePathFront'] ?>" width="400px" height="303px" align="center" alt="" /></a>
                 <a href ="something/<?php echo $row['imagePathBack'] ?>" target="_blank"><img src="<?php echo $row['imagePathBack'] ?>" width="400px" height="303px" align="center" alt="" /></a>
            </div>  
            <div class="customerComments">';
                <h5>Changes Made:</h5><br /> <?php echo $row['Comments'] ?> 
            </div>
        </div>
    <?php   
        }
    }
    else {
        echo "Wrong Username or Password";
    }
?>

</body>

</html

&GT;

CSS

.customerCards{
    top: 150px;
    position: relative;
    width: 425px;
    border: 3px;
    border-style:solid;
    border-color: black;
    background-color: silver;
    z-index:1;
}
.customerInfoMain{
    top: 200px;
    position: relative;
    width: 200px;
    left: 520px;
    border: 3px;
    border-style:solid;
    border-color: black;
    background-color: silver;
    z-index:2;
}
.customerComments{
    position: relative;
    width: 200px;
    left: 580px;
    border: 3px;
    border-style:solid;
    border-color: black;
    background-color: silver;
    z-index:2;
}

.wrapper{
    position: absolute;
    left: 50%;
    width: 900px;
    margin-left: -475px;
}

页面加载后的来源

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />

<title>Untitled 1</title>

<link href="stylesheet.css" rel="stylesheet" type="text/css" />

</head>



<body>

Wrong Username or Password

</body>



</html>

2 个答案:

答案 0 :(得分:4)

它因为你的包装器刚启动,如果有用户.. 但是如果你把你的包装器放在PHP上会发生什么,例如:

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="wrapper">
        <?php
        require("protect/serverInfo.php");
        $myusername=$_POST[Email]; 
        $mypassword=$_POST[Password];
        $result = mysql_query("SELECT * FROM Customers WHERE Email='$myusername' AND Password=$mypassword");
        $count=mysql_num_rows($result);
        if($count==1){
            while($row = mysql_fetch_array($result)){
            ?>

                <div class="customerHead">';
                    <h1>  
                        <?php echo $row['Customer'] ?> 
                    </h1>
                </div>
                <div class="customerInfoMain">
                     Company: <?php echo $row['Company'] ?><br />
                      State: <?php echo $row['State'] ?>
                </div>  
                <div class="customerCards">';
                     <a href ="something/<?php echo $row['imagePathFront'] ?>" target="_blank"><img src="<?php echo $row['imagePathFront'] ?>" width="400px" height="303px" align="center" alt="" /></a>
                     <a href ="something/<?php echo $row['imagePathBack'] ?>" target="_blank"><img src="<?php echo $row['imagePathBack'] ?>" width="400px" height="303px" align="center" alt="" /></a>
                </div>  
                <div class="customerComments">';
                    <h5>Changes Made:</h5><br /> <?php echo $row['Comments'] ?> 
                </div>

        <?php   
            }
        }
        else {
            echo "Wrong Username or Password";
        }
        ?>
    </div>
</body>
</html>

“然后你应该有一点CSS动作?”

答案 1 :(得分:0)

按目的功能拆分代码,并且计算不应该在同一个地方,html应该最后呈现。继续这样工作会给你带来很多麻烦。事情应该这样做:

loginProcess.php包含:     if(isset($ _ SESSION [“user”]){ $ row = $ _SESSION [“user”]; }     包括( “loginPage.php”); ?&GT;

这是longinPage.php(您可以在其中包含其中任何一个)。要么在loginProcess.php的末尾包含loginPage.php,要么在loginPage.php的开头包含loginProcess.php

所以loginPage.php包含

&LT; !DOCTYPE html PUBLIC“ - // W3C // DTD XHTML 1.0 Transitional // EN”“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> &LT; html xmlns =“http://www.w3.org/1999/xhtml”&gt;

&LT;头&GT; &LT; meta content =“text / html; charset = utf-8”http-equiv =“Content-Type”/&gt; &LT; title&gt; Untitled 1 &LT; link href =“stylesheet.css”rel =“stylesheet”type =“text / css”/&gt; &LT; /头&GT;

&LT;体&GT; if(isset($ _ SESSION ['user'])){

    < div class="wrapper">

        < div class="customerHead">';

            <h1><!---you know the row from before---/>  

                <?php echo $row['Customer'] ?> 

            </h1>

        </div>

        <div class="customerInfoMain">

             Company: <?php echo $row['Company'] ?><br />
              State: <?php echo $row['State'] ?>

        </div>  
        <div class="customerCards">';

             <a href ="something/<?php echo $row['imagePathFront'] ?>" target="_blank"><img src="<?php echo $row['imagePathFront'] ?>" width="400px" height="303px" align="center" alt="" /></a>

             < a href ="something/<?php echo $row['imagePathBack'] ?>" target="_blank">

&LT; img src =“”width =“400px”height =“303px”align =“center”alt =“”/&gt;

        </div>  

        <div class="customerComments">';

            <h5>Changes Made:</h5><br /> <?php echo $row['Comments'] ?> 

        </div>

    </div>

<?php   

    }

}
else {?>
     <form action="/loginProcess.php" (or loginPage.php if loginPage includes the loginProcess) method="POST">
            <input type="text" name="Email" value=""/>
            <input type="password" name="Password" value=""/>
            <input type="submit" value="login"/>
       </form>
<?php}?>

&GT;

首先会显示登录表单,用户将输入他的凭据,将检查这些凭据,如果确定,则设置SESSION ['user'](记住你需要会话启动)由于会话持续存在,您无需一直请求登录。无论如何,如果您不希望由于某种原因完全分离数据库问题/过程关注/查看问题,那么您必须将过程与查看分开(在处理区域中保持数据库关注)。在线查看一些框架或尝试找到一种更谨慎编写代码的方法,否则你将继续遇到浪费时间的无用问题。