0
matchthese=['name'=> Input::get('name'),];
Matchthose['place'=> Input::get('place')];
$Select_db = Db::table('actvities')
              ->where([[matchthese],[matchthose]])
              ->orwhere('place', Input::get('place'))
              ->orwhere('color', Input::get('color'))
              ->orwhere('people',Input::get('people'))
              ->get();

But the orwhere doesn't work correctly.I want the first one or the second one etc.How should i do this to work?

3
  • The first where works perfectly but when I choose only one of the four color ,name,place people and want for example if i choose people to go to orwhere of people it asks me the name or gives me wrong results can someone please tell me why ? Commented Jul 18, 2016 at 20:13
  • You need to be more clear what your current results are, and what your expected output is. Currently, it is ambiguous what you want. "I want the first one or the second one" do you mean you want one result only, not a collection? What do you mean it gives you the 'wrong results'. Give an example of what results you are getting vs what you expected Commented Jul 18, 2016 at 21:23
  • I want one where query to be executed or the other query each time one query should be executed based on my users choice which could be a combination of place and color or simply color I want that relationship .I am not sure that my code is correct Commented Jul 19, 2016 at 4:21

1 Answer 1

1

You can use skip and take with first:

For example for the first one you can use first directly:

$Select_db = Db::table('actvities')
              ->where([['name', '=', Input::get('name')],['place', '=', Input::get('place')]])
              ->orwhere('place', Input::get('place'))
              ->orwhere('color', Input::get('color'))
              ->orwhere('people',Input::get('people'))
              ->take(1)->first();

For the second :

$Select_db = Db::table('actvities')
              ->where([['name', '=', Input::get('name')],['place', '=', Input::get('place')]])
              ->orwhere('place', Input::get('place'))
              ->orwhere('color', Input::get('color'))
              ->orwhere('people',Input::get('people'))
              ->skip(1)->take(1)->first();

If you need to loop through the result you can simply use foreach:

$Select_db = Db::table('actvities')
              ->where([['name', '=', Input::get('name')],['place', '=', Input::get('place')]])
              ->orwhere('place', Input::get('place'))
              ->orwhere('color', Input::get('color'))
              ->orwhere('people',Input::get('people'))
              ->get();
foreach($Select_db as $record) {
    //Do something with $record.
}

I hope this will help you.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much i will try it but my proble is my orwhere which is not working correctly and i need for example the first where to be executed which is done correctly but for example when i choose only the place for the input the orwhere is not executed it askes me for the name?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.