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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:52:59+00:00 2026-06-10T04:52:59+00:00

I have a very odd problem with the following code. For some reason I

  • 0

I have a very odd problem with the following code. For some reason I can’t get $id1 or $id2 to hold values unless it is placed outside the if and else…if statements. The variables simply will not register. Does anybody see what I am doing wrong? I’m at a loss..

public function addCommentToStartpageWall() {
        $userid = $this->session->userdata("userid");
        $postingUserId = $this->input->post("postinguserid");

        $query = $this->db->query("SELECT * FROM churchmembers");
        $row = $query->row();
        foreach ($query->result() as $row) {
            if ($postingUserId == $row->cMuserId) { // check to see what church the posting user is a member of
                $id1 = $row->cMchurchId; // if posting user is a member of a church set it to var id1
            } if ($userid == $row->cMuserId) { // check to see what church myuserid is a member of
                $id2 = $row->cMchurchId; // if myuserid is a member of a church set it to var2
            } if ($id1 == $id2) { // if posting user and myuserid are a member of the same church process the following
                echo json_encode(array('id1' => $id1, 'isMembershipSame' => true));
            } elseif ($id1 != $id2) { // if posting user and myuserid are not a member of the same user process the following
                echo json_encode(array('id1' => $id1, 'isMembershipSame' => false));
            }
        }
    }
  • 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-10T04:53:01+00:00Added an answer on June 10, 2026 at 4:53 am

    Looks like i was wrong too, above answer is correct.

    I would recommend resetting your $id1 and $id2 variables each loop however, to prevent them from holding values from the previous iteration:

    foreach ... 
    {
        $id1 = "";
        $id2 = "";
    
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very odd problem with javascript. My code is rather long so
I have very odd problem and I don't know how to get rid of
I'm having a very odd problem that I can't understand. I have created an
Ok, so I have some problems with C++ iostreams that feels very odd, but
i have very serious problem if any tech expert can help...thank you in advance..
I have a very odd problem. A class property is mysteriously reset between method
We have a very odd problem here with SVN. Let me first explain the
This is my first question on S.O. I have a very odd problem. Below
I have a very odd problem with unobtrusive validation. I have a model with
I have an odd problem with the following: function loadTextbox(jsonUrl,divId){ $.getJSON(jsonUrl, function(json) { $('#'

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.