我要循环出很多数据来创建表,但是在文件底部循环终止后,出现了EOF PHP错误。这是一种独特的语法,但是我认为代码没有问题。这是代码(从第一个foreach循环开始):
<div class="tbody">
<?php foreach ($extra_html['data'] as $referrers) { ?>
<div class="tr-container">
<div class="tr" data-referral-id="28401">
<div class="referral-data-container">
<span class="data blue referred-by"><?=$referrers['referrer']?></span>
<span class="data referral-number"><?=$referrers['referrals_made']?></span>
<span class="data blue qualified-number"><?=$referrers['referrals_qualified']?></span>
<span class="data sold-number green"><?=$referrers['referrals_sold']?></span>
<input type="text" value="$<?=$referrers['next_payout_amount']?>" class="data-input next-payout-amount input-widths" style="margin-right:25px;">
<input type="date" value="<?=($referrers['next_payout_date'] === '0' ? 'yyyy-MM-dd' : $referrers['next_payout_date'])?>" class="data-input next-payout-date input-widths" style="margin-right:25px;">
<input type="text" value="<?=$referrers['salesperson']?>" class="data-input salesperson input-widths">
</div>
<div class="plus-sign"></div>
</div>
<div class="nested-table">
<div class="nested-thead">
<div>
<span class="heading number-width">#</span>
<span class="heading referral-name-width">Referral</span>
<span class="heading referral-date-width">Referral Date</span>
<span class="heading status-width">Status</span>
<span class="heading checkboxes-width">Qualified Payout</span>
<span class="heading input-widths">Sold Payout</span>
</div>
</div>
<div class="nested-tbody">
<?php for ($i = 0; $i < count($referrers['referrals']); $i++) { ?>
<div class="nested-tr">
<span class="data number-width"><?=$i?></span>
<span class="data blue referral-name-width" onclick="showReferralModal(this)"><?=$referrers['referrals'][$i]['referral']?></span>
<span class="data referral-date-width"><?=$referrers['referrals'][$i]['date_added']?></span>
<div class="status-width">
<select>
<option selected>New Referral</option>
<option>Qualified Referral</option>
<option>DQ'd Referral</option>
<option>Sold Referral</option>
</select>
</div>
<div class="checkboxes-width">
<input type="checkbox" class="qualified-payout-checkbox blue">
</div>
<div class="checkboxes-width">
<input type="checkbox" class="sold-payout-checkbox blue">
</div>
</div>
<? } ?>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<div class="modal-container">
<div class="white-box">
<div class="top">
<h3>Name Here</h3>
<div class="close" onclick="closeModal()"></div>
</div>
</div>
</div>
<script src="/js/referral.js"></script>
<?php include_once '../view/includes/footer_nav.php'; ?>
<?php include_once '../view/includes/footer.php'; ?>
为解释独特的语法,我在关闭内部for循环之后关闭了三个封闭div标签(</div>
)的第一个foreach循环。 EOF错误出现在最后一个include_once
语句之后。我这样做是为了可以从我的IDE(Sublime)中突出显示语法。我尝试执行以下语法:
<?php foreach ($extra_html['data'] as $referrers): ?>
// html
<?php for ($i = 0; $i < count($referrers['referrals']); $i++): ?>
// more html
<?php endfor; ?>
// html
<?php endforeach; ?>
但是我遇到了“意外的foreach语句”错误。
所以我想我的问题有两个方面:
如何通过我目前正在做的所有事情来解决EOF错误?如果答案是否定的,这样做的更好方法是什么?
答案 0 :(得分:1)
我不确定,但是这种语法对我来说似乎不正确:
</div>
<? } ?>
</div>
如果是这样的话,将是一个非常简单的解决方法;)