我有2個獨立的foreach循環在下面的代碼中執行。最後,我有$ row-> websiteURL在第二個foreach循環後輸出。問題是$ row-> websiteURL是第一個循環的一部分。所以,我得到以下錯誤,當我運行代碼:CodeIgniter繼續運行一個foreach循環後
一個PHP錯誤遇到
嚴重性:注意
消息:未定義的屬性:stdClass的:: $ websiteURL
文件名:視圖/ projects.php
行號:135
「目標=」 _空白「>
如何繼續第二個foreach完成後的第一個foreach循環?
<table style="width: 41%">
<?php $query = $this->db->query("SELECT * FROM projects ORDER BY idprojects DESC");
foreach ($query->result() as $row) { ?>
<tr>
<td style="height: 15px">
<div class="auto-style2">
<em><span class="auto-style1"><?=$row->projectName?></span></div>
<table cellpadding="5" style="width: 535px; height: 66;">
<tr>
<td class="box1" style="height: 49px; width: 800px;">
<table cellpadding="0" cellspacing="0" style="width: 466px; height: 185px">
<!-- MSTableType="layout" -->
<tr>
<td valign="top" style="width: 225px">
<em>
<table style="width: 100%">
<tr class="box1">
<td class="innerbox" style="height: 88px"><em><span class="text1">Project name</span>:
<span class="underlined-link"><?=$row->projectName?></span><br>
<span class="text1">Description</span>: <?=$row->projectDesc?><br><span class="text1">Start
date</span>: <?=$row->startDate?><br><span class="text1">Finised date</span>:
<?=$row->finishedDate?><br><span class="text1">Created for</span>:
<?=$row->createdFor?><br><span class="text1">Contributers</span>:
<span class="underlined-link"><?=$row->contributors?></span></em></td>
</tr>
</table>
</em></td>
<td style="width: 12px"> </td>
<td valign="top" style="height: 185px; width: 229px">
<em>
<?php $query = $this->db->query("SELECT * FROM screenshots ORDER BY idscreenshot DESC");
foreach ($query->result() as $row) { ?>
<img alt="" src="<?=$row->screenshotURI?>" width="231" height="187"></em> </td>
</tr>
<?php } ?>
</table>
<br>
<a style="text-decoration:none" href="<?=$row->websiteURL?>" target="_blank"><div class="link1">
View This Product</div></a>
</td>
</tr>
</table>
</em></td>
</tr>
<?php } ?>
</table>
首先,你爲什麼要在你的視圖中查詢數據庫?這應該在模型中完成。給我一秒鐘,我一步一步通過這一點。 – 2012-04-18 21:57:19