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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:21:47+00:00 2026-06-05T18:21:47+00:00

I have a form on which I have a multiselect for different boxes and

  • 0

I have a form on which I have a multiselect for different boxes and for boxes there exists some records i-e (the number of openings of the box) in the database but it might be possible that for a selected box no records exists ie (the box is not opened even single time). Currently when I select different boxes and if records does not exist for a box it does not return the empty array for that box I want to it return even the empty results for the selected box. My query is

public function getBoxOpenings($boxes, $from_date, $to_date){
$query = $this->db->select('box_id, COUNT(box_id) AS Openings')
    ->from('boxes')
    ->where_in('box_id', $boxes)
    ->where('actiontime >=', $from_date)
    ->where('actiontime <=', $to_date)
    ->group_by('box_id')
    ->get();
$data = $query->result_array();
return $data;
}

If I select 3 boxes and submit the form and records exists for only 2 boxes it returns something like this

 Array
(
[0] => Array
    (
        [mc_boxes_idmc_boxes] => 12
        [location] => FRA-Air
        [Openings] => 1
    )

[1] => Array
    (
        [mc_boxes_idmc_boxes] => 14
        [location] => FRA-Hof
        [Openings] => 1
    )

)

How can I get all three records with one empty like this

[2] => Array
    (
        [mc_boxes_idmc_boxes] => 16
        [location] => Test
        [Openings] => 
    )

How Can I get the records for all the selected boxes with empty arrays for those which have no records.

Thanks

  • 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-05T18:21:48+00:00Added an answer on June 5, 2026 at 6:21 pm

    The problem here is obvious: You only insert a row into that table when the box is opened by user. If the box not opened ever that table contains no record for that box.

    If You then do a select * from table where id in (1, 2, 3, 4, 5) but Your table contains only rows for ids 2 and 3, the result set will contain only the data for the ids 2 and 3 as there are no records found for other ids.

    I guess You only could call this query in a loop for each $box_id from $boxes – when the data is found return it otherwise return zero. Like this:

    public function getBoxOpenings($boxes, $from_date, $to_date){
        $data = array();
        foreach($boxes as $box) {
            $query = $this->db->select('box_id, COUNT(box_id) AS Openings')
                ->from('boxes')
                ->where('box_id = ', $box)
                ->where('actiontime >= ', $from_date)
                ->where('actiontime <= ', $to_date)
                ->group_by('box_id')
                ->get();
            $res = $query->result_array();
            if($res)
                $data[] = $res;
            else
                $data[] = array('box_id' => $box, 'Openings' => 0);
        }
        return $data;
    }
    

    But this is not very nice as You do one query per each box that will be very resource consuming when having a lot of boxes…

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

Sidebar

Related Questions

i have to send form data which have multiselect boxes to a servlet using
I have a form which is passing a number array like (56,78,98) . I
I have django form which displays the check boxes.After selecting the checkboxes user will
I have the following multiselect control in a Ext JS form which looks like
i have a multiselect box (of interests) in my zend form, and i am
I have a form with a multiselect field with several options, which looks like
I have a form which has some input fields along with file object. Once
I have a form which is posted to an external API. There is a
I have form in which there are 5 inputs I need to check From
I have a form which has a collection for manager which is an autocomplete

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.