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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:28:11+00:00 2026-06-16T02:28:11+00:00

I wanted to know how to check whether there is a value present in

  • 0

I wanted to know how to check whether there is a value present in a table (managers) and then add a ‘yes’ or ‘no’ string depending on if there is a value in that table or not.

$this->db->select('employees.first_name, employees.last_name, departments.department_name, departments.department_numb, titles.title');
            $this->db->from('employees');
            $this->db->where('first_name', $firstname);
            $this->db->where('last_name', $lastname);
            $this->db->join('department_manager', 'department_manager.emp_numb = employees.emp_numb', 'inner');
            $this->db->join('departments', 'departments.department_numb = department_manager.department_numb', 'inner');
            $this->db->join('titles', 'titles.emp_numb = employees.emp_numb', 'inner');
            $this->db->where('department_name', $dept);
            $this->db->where('title', $jobtitle);
            $result = $this->db->get();

            $data = array();
            foreach($result->result() as $row)
            {
                $entry = array();
                $entry['firstname'] = $row->first_name;
                $entry['lastname'] = $row->last_name;
                $entry['jobtitle'] = $row->title;
                $entry['dept'] = $row->department_name;
                $entry['deptid'] = $row->department_number;
                //$entry['ismanager'] = 

                $data[] = $entry;
            }
            return $data;

I want to check whether an employee is present in the table 'department_manager' which is joined by an employees number. So if that employee number is not present in the table ‘department_manager’ then I want to insert in the array index $entry[ismanager'] a string which says ‘no’, and if the employee number is present in the table ‘department_manager’ then I want $entry['ismanager'] to hold the string ‘yes’.

But I’m confused as to how to check that the employee is present or not in that table. Do I do it in the active record query or in the foreach loop? And if it is done in the foreach loop then how do I make that comparison as the query is completed?

  • 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-16T02:28:12+00:00Added an answer on June 16, 2026 at 2:28 am

    Why have a field that is basically a calculated value? That’s like having fields for quantity per box, quantity of boxes then saving the total items to a third field. Never save to the database something you can gain access to via a quick query. In your query above it’s as simple as changing the dept manager join to a left join, including the dept manager id and saying if that field is blank in a record the person is not a manager. Using a LEFT join will return all records whether they have an entry in the management table or not.

    Add: department_manager.emp_numb to the select.

    The Join:

    $this->db->join('department_manager', 'department_manager.emp_numb
    = employees.emp_numb', 'left');
    

    Then in the foreach:

    if(!$row->department_manager.emp_numb)
     {
        this person is not a manager;
     } 
    

    If you feel you really must have that extra field then you can still populate it with the method above.

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

Sidebar

Related Questions

I know that there are better ways to check for an empty string—bear with
I wanted to know if data is present then there must be mysql update
I wanted to know is it possible to check that a device can send
I know there is an easier way of making things work to check whether
I just wanted to know that whether the output of printing the session object
I just wanted to know if I need to place a check for null
i just wanted to know if it is possible to check in mouse event
Wanted to know if there was a way one could query shelveset details from
Wanted to know if someone had a suggestion on code or maybe there's a
I wanted to know that if I am doing correctly, regarding retain and release

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.