2011-02-01 125 views
0

由於某些原因,我的CSS不會將我的div標籤格式化爲頁面上的正確位置。它適用於我所有的其他頁面,但是這個頁面比正常頁面有更多的PHP,我想知道這是否是問題所在。 頁PHP,HTML和CSS的頁面佈局問題

<!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 

>

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> 
+1

PHP在服務器端運行,並且從不出現在輸出中。您需要查看生成的HTML(並可能在此處發佈) – 2011-02-01 08:04:13

回答

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操作?」

0

按功能劃分代碼功能和計算並不意味着在同一個地方,html應該最後呈現。繼續這樣工作會給你帶來很多麻煩。事情應該做的是這樣的:

loginProcess.php包含: 如果(isset($ _ SESSION [ 「用戶」]){$ 排= $ _SESSION [ 「用戶」];} 包括 (「loginPage .php「); ?>

並且這是longinPage.php(你可以在其中包含任何一個),或者在loginProcess.php結尾包含loginPage.php,或者包含loginProcess.php loginPage.php開頭

so loginPage.php contains

<!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;字符集= UTF-8" HTTP的當量= 「內容類型」/> <標題>無標題1 <鏈路HREF = 「stylesheet.css中」 的rel = 「樣式表」 類型= 「文本/ CSS」/> < /頭>

<體> 如果(isset($ _ SESSION [ '用戶'])){

< 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"> 

< IMG SRC = 「」 寬度= 「400像素」 HEIGHT = 「303px」 ALIGN =」中心「alt =」「/>

 </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}?> 

?>

第一登錄表單將被顯示,並且用戶將輸入他的憑證,這些證書將被檢查,並且如果他們確定的SESSION [「用戶」]被設定(remeber你需要爲此啓動會話)現在只要會話持續存在,您就不需要始終請求登錄。無論如何,如果您不希望由於某種原因將數據庫問題/流程問題/查看問題完全分開,那麼您必須將流程與查看分開(在處理區域保留數據庫問題)。在網上檢查一些框架或試圖找到一種方法來編寫更仔細的代碼,否則你將繼續有無用的問題,浪費你的時間。