0

I'm looping out a lot of data to create tables, but after the loop has terminated at the bottom of the file I'm getting an EOF PHP error. This is kind of unique syntax, but I don't see a problem with the code. Here is the code (starting with the first foreach loop):

            <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'; ?>

To explain the unique syntax, I'm closing the first foreach loop three closing div tags (</div>) after I'm closing the inner for loop. And the EOF error is coming after the last include_once statement. I'm doing it this way so I can get syntax highlighting from my IDE (Sublime). I tried doing this syntax:

<?php foreach ($extra_html['data'] as $referrers): ?>
    // html
    <?php for ($i = 0; $i < count($referrers['referrals']); $i++): ?>
        // more html
    <?php endfor; ?>
    // html
<?php endforeach; ?>

But I was getting an "unexpected foreach statement" error.

So I guess my question is kind of two fold:
How can I fix the EOF error with how I'm currently doing everything? And if the answer is no, what is the better way of doing this?

Adam McGurk
  • 186
  • 1
  • 19
  • 54
  • I personally prefer the second way as it's more readable. Sounds like you had some sort of typo going on before the foreach and the error message just said "what's this foreach doing here?" Probably an unclosed quote or something like that. – Tim Morton Jun 10 '19 at 23:10

1 Answers1

1

Well I don't know for sure, but this syntax doesn't seem right to me:

                    </div>

                    <? } ?>

                </div>

Would be a really simple fix if that's the case ;)

YTZ
  • 876
  • 11
  • 26
  • Are you saying change it to that? I'll try that – Adam McGurk Jun 10 '19 at 23:04
  • HOLY COW!!!! No, you were saying that was the problem...that fixed it!!!!! Thank you!! When you're staring at the same code for hours, it looks like that stuff just gets away from you....THANK YOU!!! – Adam McGurk Jun 10 '19 at 23:06
  • @AdamMcGurk Haha we've all been there. You're welcome. (please don't forget to accept the answer, need that streetcred) – YTZ Jun 10 '19 at 23:10
  • Please don't answer questions where the solution is "Fix the typo". This type of question has no long term value since other people with the same problem are not going to find this by searching. "Typo" is one of the standard Close Vote reasons. Answering this type of question can block the OP from deleting it to remove bloat from StackOverflow. – John Conde Jun 10 '19 at 23:12
  • @JohnConde Ah good to know. – YTZ Jun 10 '19 at 23:15