我是PHP新手。我有一些問題能夠使用嵌套for循環打印多個表。所以對於當前的代碼,我有一個嵌套for循環,只打印出1個表格,這與我在外部循環時得到的相同。我在數組中有一些硬編碼的數據,我希望嵌套for循環能夠打印出4張相同的表格。出於某種原因,這不是基於我的工作,我似乎無法弄清楚爲什麼它不是。在PHP中使用嵌套循環打印多個表格
最終,我們將從數據庫中提取硬編碼數據。我們必須從一個需要根據會議正確填充順序的數據庫中提取數據,並基於我目前的邏輯,我想知道這是否仍然是基於我指導自己的方式的可能性。我真的想弄明白這一點,並希望解釋爲什麼它不起作用。謝謝大家!
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>
<?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');
for ($i = 0; $i<4; $i++)
{
$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];
echo '<tr><td>'.$highSeed.'</td><tr>';
}
echo '</table>';
echo "\n";
}
?>
<body>
</body>
</html>
謝謝!這工作,我可能掃描了代碼100次,但我只是沒有注意到這個小小bug – user2522055