次のコードには非常に奇妙な問題があります。何らかの理由で、if および else...if ステートメントの外に配置しない限り、$id1 または $id2 に値を保持させることができません。変数は単に登録されません。誰かが私が間違っていることを見ていますか? 私は途方に暮れています..
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));
}
}
}