我有一個數組$eps
來自MYSQL表,我想輸出它的內容到下面的html格式。我試圖使用foreach循環來輸出內容,但季節值正在包裹所有細節div。 下面的代碼是什麼,我只能想到PHP數組格式的HTML輸出
foreach($eps as $key){
foreach($key as $k){
echo "<div class='main'>";
echo "<div class='season'>".$k['season'];
echo "<div class='details'>";
echo "<div class='ep'>".$k['episode']."</div>";
echo "<div class='title'>".$k['title']."</div>";
echo "<div class='airdate'>".$k['airdate']."</div>";
echo "<div class='plot'>".$k['plot']."</div>";
echo "</div>";
echo "</div>";
echo "</div>";
}
}
數組內容
Array
(
[1] => Array
(
[0] => Array
(
[title] => Pilot: Part 1
[date] => Sep. 22, 2004
[plot] => Forty-eight survivors of an airline flight originating from Australia, bound for the
[season] => 1
[episode] => 1
)
[1] => Array
(
[title] => Pilot: Part 2
[date] => Sep. 29, 2004
[plot] => Jack, Kate and Charlie return to the group, but the transceiver is broken. Sayid Jarrah
[season] => 1
[episode] => 2
)
[2] => Array
(
[0] => Array
(
[title] => Man of Science, Man of Faith
[date] => Sep. 21, 2005
[plot] => One of the castaways is chosen to descend into the mysterious hatch, and Shannon stumbles
[season] => 2
[episode] => 1
)
[1] => Array
(
[title] => Adrift
[date] => Sep. 28, 2005
[plot] => After the raft explodes, Michael and Sawyer are left on what is left on the raft. They
[season] => 2
[episode] => 2
)
CSS
.main {
width: 750px;
margin-right: auto;
margin-left: auto;
clear: both;
overflow:auto;
}
.season {
margin: 5px;
padding: 5px;
width: 730px;
background: #960;
clear: both;
overflow:auto;
display: block;
}
.details {
display: block;
float: right;
border-bottom: thin solid #000;
}
.ep, .title, .airdate, .plot {
margin: 5px;
padding: 5px;
width: 675px;
background: #CCC;
}
所以最新的問題是什麼?你想達到什麼目的?你似乎有輸出工作。 – Jakub 2012-02-07 21:26:17
我想在劇集細節下展示一季。比下個賽季等等.. – 2012-02-07 21:30:15
@BhaskarWankhede我編輯了我的答案兩次,你能檢查它嗎? – motto 2012-02-07 21:33:24