2014-02-08 37 views
0

從任何地方我看起來和研究似乎也可以把標籤內的PHP代碼,但由於某種原因,只有當我的標籤是在PHP以外的作品。我似乎無法找出它的問題。我試圖在裏面打印的原因是因爲我試圖創建一個嵌套for循環。目前我註釋掉了PHP以外的表格標籤,並將它們打印在php代碼中。目前這是行不通的。這是我的代碼,並再次感謝你。桌面打印只有當<table>標籤以外的PHP標籤

<?php print('<?xml version = "1.0" encoding = "utf-8"?>') ?> 
<!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>User selection page</title> 
    </head> 

    <!-- <table border="1px"> --> 
    <!-- <tbody> --> 
    <?php 
     /* 
     Version 1.1: Instead of printing the teams in different cells we are going to print the 
     games in one row and we select the game itself to see if an upset will occur. 
     */ 


     require_once('Conference.php');   
     $loadGameClass = new Conference(); 
     $loadGameClass->loadTeams(array("(1)Gonzaga vs (16)Southern U", "(8)Pittsburgh vs (9)Wichita St", "(5)Wisconsin vs (12)Ole Miss", "(4)Kansas st vs (13)Boise St", "(6)Arizona vs (11)Belmont", "(3)New Mexico vs (14) Harvard", "(7)Notre Dame vs (10)Iowa St", "(2)Ohio St vs (15) Iona")); 
     $teams = $loadGameClass->getTeams(); 

     echo "<table border="1">"; 

     for ($i = 0; $i < 8; $i++) 
     { 
     $highSeed = $teams[$i]; 
     //$lowSeed = $teams[((2*8)-1)-$i]; 
     echo "<tr><td>$highSeed</td>"; //<td>$lowSeed</td></tr> 
     } 

     echo "</table>"; 
    ?> 
    <!-- </tbody> --> 
    <!-- </table> --> 

    <body> 
    </body> 
</html> 

回答

1

第一個問題是

echo "<table border="1">"; 

應該

echo '<table border="1">'; 

然後

echo "<tr><td>$highSeed</td>"; 

更好的辦法是

echo '<tr><td>'.$highSeed.'</td></tr>'; 
+0

我上次做過表標記而不是tr或td標記,所以可能是問題所在!謝謝你解決這個問題! – user2522055

+0

是的,它更好地分離的HTML和PHP,我更喜歡連接,因爲我在答案中。 –