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 834619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:41:59+00:00 2026-05-15T04:41:59+00:00

I have two foreach statements. The variable from one one is somehow getting into

  • 0

I have two foreach statements. The variable from one one is somehow getting into another and i’m not sure how to fix it.

Here’s my controller:

// Categories Page Code
    function categories($id)
    {
        $this->load->model('Business_model');
        $data['businessList']   = $this->Business_model->categoryPageList($id);
        $data['catList']    = $this->Business_model->categoryList();
        $data['featured']   = $this->Business_model->frontPageList();
        $data['user_id']    = $this->tank_auth->get_user_id();
        $data['username']   = $this->tank_auth->get_username();
        $data['page_title'] = 'Welcome To Jerome - Largest Ghost Town in America';
        $data['page'] = 'category_view'; // pass the actual view to use as a parameter
        $this->load->view('container',$data);

    }

What happens is categories will only show the businesses in a certain category.

The businesses are pulled from the database using the categoryPageList($id) function.

Here is that function:

function categoryPageList($id) {
    $this->db->select('b.id, b.busname, b.busowner, b.webaddress, p.thumb, v.title, c.catname, s.specname, p.thumb, c.id');
    $this->db->from ('business AS b');
    $this->db->where('b.category', $id);
    $this->db->join('photos AS p', 'p.busid = b.id', 'left');
    $this->db->join('video AS v', 'v.busid = b.id', 'left');
    $this->db->join('specials AS s', 's.busid = b.id', 'left');
    $this->db->join('category As c', 'b.category = c.id', 'left');
    $this->db->group_by("b.id");
    return $this->db->get();
}

And here is the view:

<h2>Welcome to Jerome, Arizona</h2> 

<p>Choose the Category of Business you are interested in:<br/> <?php foreach ($catList->result() as $row): ?>
            <a href="/site/categories/<?=$row->id?>"><?=$row->catname?></a>, &nbsp;
            <?php endforeach; ?></p>


<table id="businessTable" class="tablesorter">
    <thead><tr><th>Business Name</th><th>Business Owner</th><th>Web</th><th>Photos</th><th>Videos</th><th>Specials</th></tr></thead>
        <?php if(count($businessList) > 0) : foreach ($businessList->result() as $crow): ?>

            <tr>
                <td><a href="/site/business/<?=$crow->id?>"><?=$crow->busname?></a></td>
                <td><?=$crow->busowner?></td>
                <td><a href="<?=$crow->webaddress?>">Visit Site</a></td>
                <td>
                    <?php if(isset($crow->thumb)):?>
                    yes
                    <?php else:?>
                    no
                    <?php endif?>

                </td>

                <td>
                    <?php if(isset($crow->title)):?>
                    yes
                    <?php else:?>
                    no
                    <?php endif?>


                </td>
                <td>
                    <?php if(isset($crow->specname)):?>
                    yes
                    <?php else:?>
                    no
                    <?php endif?>


                </td>
            </tr>
        <?php endforeach; ?>

        <?php else : ?>
        <td colspan="4"><p>No Category Selected</p></td>

        <?php endif; ?>

</table>

The problem occurs here. <?=$crow->id?> should be showing the row id from the business table. Instead, it’s showing the row ID of the category table. so, if i’m viewing /site/categories/6 <?=$crow->id?> will show 6 when it should be showing 10 (the row ID of the only business in that category at this time.

How can I fix this?

  • 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-05-15T04:42:00+00:00Added an answer on May 15, 2026 at 4:42 am

    Your SELECT clause in categoryPageList contains two id columns; both that of the business and category table. Thus, you only fetch the business id.

    $this->db->select('b.id, b.busname, b.busowner, b.webaddress, p.thumb, v.title, c.catname, s.specname, p.thumb, c.id');

    Removing b.id should do the trick.

    $this->db->select('b.busname, b.busowner, b.webaddress, p.thumb, v.title, c.catname, s.specname, p.thumb, c.id');

    In case you need both values give them aliases.

    $this->db->select('b.id business_id, b.busname, b.busowner, b.webaddress, p.thumb, v.title, c.catname, s.specname, p.thumb, c.id category_id');

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 430k
  • Answers 431k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can try git push --force to force the push.… May 15, 2026 at 2:06 pm
  • Editorial Team
    Editorial Team added an answer From "custom authentication" and "[when] a few dozens of clients… May 15, 2026 at 2:06 pm
  • Editorial Team
    Editorial Team added an answer Do this processing for each of the lines in the… May 15, 2026 at 2:06 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.