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

  • Home
  • SEARCH
  • 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 8830809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:10:40+00:00 2026-06-14T08:10:40+00:00

If I got this: $result = DB::select( ‘orders.date_created’ ) ->from(‘orders’) ->execute()->as_array(); For normal, dsiplaying

  • 0

If I got this:

    $result = 
    DB::select(
    'orders.date_created'
    )
    ->from('orders') 
    ->execute()->as_array();

For normal, dsiplaying all orders date_created. Now I can filter by user, doing this ?user_id=112

This will make me having this:

    if(isset($get['user_id']))
    {
        $result = 
        DB::select(
        'orders.date_created'
        )
        ->from('orders') 
                    ->where('user_id', '=', $get['user_id'])
        ->execute()->as_array();
    }else{
        $result = 
        DB::select(
        'orders.date_created'
        )
        ->from('orders')
        ->execute()->as_array();
    }

Although this is no problem for me have this, but this get to be real much ugly code when I have 4 params to filter out from(4 where statements) e.g ?user_id=112&quantity=2&…

Can I somehow make a inline if/action statement, which would grab all user_ids if there’s nothing in $get[‘user_id’] ?

So I can end up having only this:

        $result = 
        DB::select(
        'orders.date_created'
        )
        ->from('orders') 
                    ->where('user_id', '=', (isset($get['user_id']) ? $get['user_id'] : 'GRAB ALL!'))
        ->execute()->as_array();

or is there another, even better way to do this?

Tried looking in Kohana docs if there’s some ->if()->where()->exitif().. (just some imagination of how it could work)

  • 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-14T08:10:41+00:00Added an answer on June 14, 2026 at 8:10 am

    You can modify Query object before executing:

    $query = DB::select()->from(...);
    if (isset($get['user_id'])) {
        $query->where('user_id', '=', intval($get['user_id']));
    }
    if (isset($get['quantity'])) {
        $query->where('quantity', '=', floatval($get['quantity']));
    }
    $result = $query->execute()->as_array();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a result from remote database as a Result set like this: String
I've got this raw query : counters = Counter.objects.raw( SELECT id, name FROM building_counter
i've got this union query: (SELECT INSTALLER, INSTALLTIME, RESULT, JOBNUMBER, HONAME, ADDRESS, CITY, STATE,
So far i got this code: function toplist() {$sql = SELECT * FROM list
I have got this result with the answer given by bluefeet Equipt BSL AQ
I am using SOAP , and got this returnString. <?xml version=1.0 encoding=UTF-8 ?> <result>
For the following echo 0.02-0.01-0.06+0.05; I got result is 6.93889390391E-18 For this one echo
Got this code for a viewscroller from the apple developers site. @synthesize scrollView1, scrollView2;
I've got this query: SELECT TOP 1 A.ExamTemplateId, A.Id AS AnsweredTestId, AVG(B.Score) AS AvgScore,
in my doctrine table i got this public function countHitsFor($object_id) { return $this->createQuery('s') ->select('COUNT(*)

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.