Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8737893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:37:27+00:00 2026-06-13T10:37:27+00:00

This has me stumped. I can print_r the array called $item_pages and it outputs

  • 0

This has me stumped. I can print_r the array called $item_pages and it outputs all of the keys and values correctly. However, once that array is used within the foreach, it seems to become empty. This is the array when I print_r outside of the foreach:

Array ( [0] => 1 [1] => 6 [2] => 12 [3] => 15 [4] => 16 [5] => 17 [6] => 18 [7] => 19 [8] => 78 [9] => 79 [10] => 87 [11] => 90 [12] => 94 [13] => 95 [14] => 98 [15] => 99 [16] => 102 [17] => 103 [18] => 105 [19] => 107 [20] => 108 [21] => 110 [22] => 111 [23] => 112 [24] => 113 [25] => 114 [26] => 119 [27] => 120 [28] => 121 [29] => 125 [30] => 126 [31] => 134 [32] => 135 [33] => 136 [34] => 138 [35] => 142 [36] => 186 [37] => 193 [38] => 197 [39] => 198 [40] => 199 [41] => 206 [42] => 327 [43] => 452 [44] => 470 [45] => 487 [46] => 601 [47] => 614 [48] => 630 [49] => 684 [50] => 726 [51] => 727 [52] => 789 [53] => 871 )

Here’s the controller:

    public function view_item_pages() {

    if ($this->input->is_ajax_request()) {

      $item_id = $this->input->post('item_id');
      $this->data['item_id'] = $item_id;
      $this->data['pages'] = $this->affiliate_model->get_all_affiliates();
      $this->data['item_pages'] = $this->item_model->get_item_pages($item_id);

      $this->load->view('/admin/item/pages', $this->data);

    }

  }

Here’s the view:

<fieldset>
    <table id="all-pages" class="table table-striped table-bordered">
        <thead>
          <tr>
            <th><input type="checkbox" class="checkbox" id="select_all"></th>
            <th>ID</th>
            <th>Name</th>
          </tr>
        </thead>
        <tbody>

        <?php foreach ($pages as $page): 

            $checked = FALSE;

            if (!empty($item_pages)) {
                if (in_array($page['aff_id'], $item_pages)) {
                    $checked = TRUE;
                }
            }
        ?>
              <tr>
                <td><?php echo form_checkbox('page', $page['aff_id'], $checked); ?></td>
                <td><?php echo $page['aff_id']; ?></td>
                <td><?php echo $page['name']; ?></td>
              </tr>

        <?php endforeach; ?>

        </tbody>
    </table>
</fieldset>

So if I do the following, the array works:

    <?php print_r($item_pages); ?>

    <?php foreach ($pages as $page):

        $checked = FALSE;

        if (!empty($item_pages)) {
            if (in_array($page['aff_id'], $item_pages)) {
                $checked = TRUE;
            }
        }
    ?>

If I do this, it doesn’t return anything, it’s like doing echo '';:

   <?php foreach ($pages as $page):

        print_r($item_pages);

        $checked = FALSE;

        if (!empty($item_pages)) {
            if (in_array($page['aff_id'], $item_pages)) {
                $checked = TRUE;
            }
        }
    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:37:28+00:00Added an answer on June 13, 2026 at 10:37 am

    In your controller print $pages. If $pages is empty the execution does not enter the foreach loop inside the view.

    $this->data['pages'] = $this->affiliate_model->get_all_affiliates();
    print_r($this->data['pages']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has me stumped - hopefully someone can point out an obvious error. I
This has me stumped. The follow code returns ,,,,,,: <script type=text/javascript> $(function() { $('#listB').sortable({
This one has me stumped. <div id=container> <div id=store></div> <div id=contact></div> </div> I'm looking
This one has me stumped. Here are the relative bits of code: public AgencyDetails(Guid
This one has me stumped. I need to call an activity method from within
I'm really stumped by this one! The StackFrame object ( MSDN Link ) has
This has probably something to do with my transformations, but right now I can't
This one has me stumped, and none of the other related questions here have
This is probably a very simple question for some, but it has me stumped.
This is probably a very simple question for some, but it has me stumped.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.