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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:42:16+00:00 2026-05-20T01:42:16+00:00

I’m doing the following queries in codeigniter and can’t figure out how to get

  • 0

I’m doing the following queries in codeigniter and can’t figure out how to get the second query to work. How do I get an array of just the values from my first query and use that in my second?

function application()
{
    $user_id = $this->tank_auth->get_user_id();
    $this->db->select('app_id')->from('using')->where('user_id' , $user_id);
    $query = $this->db->get();

    $row = $query->result_array();

    if ($query->num_rows() > 0) :
    $this->db->select('app_name')->from('applications')->where('id' , $row['app_id']);
    $body['query'] = $this->db->get();
    endif;

    $this->load->view('apps_view', $body);

If I comment out the second query and var_dump($row);
it gives me:
array(2) { [0]=> array(1) { [“app_id”]=> string(1) “2” } [1]=> array(1) { [“app_id”]=> string(1) “3” } }

I decided to do multiple queries instead of a join because I will be adding additional columns to select from the second query.

Thanks for the help.

  • 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-20T01:42:17+00:00Added an answer on May 20, 2026 at 1:42 am

    Are you expecting the first query to return just one row?

    If so then you should use:

    $query = $this->db->get();
    
    $row = $query->row();
    
    $app_id = $row->app_id;
    //etc
    

    It’s not clear from your question.

    If your first query returns (or can return) multiple rows, then you need to do this:

    $query = $this->db->get();
    
    if ($query->num_rows() > 0) :
        foreach($query->result_array() as $row)
        {
            $this->db->select('app_name')
                     ->from('applications')
                     ->where('id' , $row['app_id']);
        }
    
        $body['query'] = $this->db->get();
    endif;
    // etc
    

    you very may well need to adjust the code as I’m not sure what your desired result is. Do you see the difference?

    If you return result_array you have an array of results (fancy that!) – hence why your var_dump has [0]=> array(1) etc – there is an array for each row returned.

    If you are only wanting/expecting to return one result from the first query, you should use row instead.

    Hope this makes sense – should be a push in the right direction.

    edit
    In fact this might be the correct syntax:

    $query = $this->db->get();
    
    if ($query->num_rows() > 0) :
        $this->db->select('app_name')->from('applications');
        foreach($query->result_array() as $row)
        {
            $this->db->where('id' , $row['app_id']);
            // build the `where...` string with iteration/result/row
        }
    
        $body['query'] = $this->db->get(); // now we get the data.
    endif;
    // etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I'm doing something wrong, but I can't figure out what I'm doing
hope someone can figure out what I'm doing wrong here. The task seems quite
Currently I am doing mass deletes using variations of the following query: DELETE FROM
I'm doing the following and always get green pins: pin.pinColor = MKPinAnnotationColorRed; [self.mapView addAnnotation:pin];
I am doing the following: $type = 'attachment'; $images = $wpdb->get_results($wpdb->prepare(' SELECT p.* FROM
We are trying to optimize some of our queries. One query is doing the
I'm doing a small test. The following code runs 3 random queries 1000 times
In try to create a spreadsheet that is generated from multiple queries, the following
I've tried following the PHP.net instructions for doing SELECT queries but I am not
Using the example Models from https://docs.djangoproject.com/en/dev/topics/db/queries/ I want to do something like the following:

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.