9

Having a hard time here trying to retrieve specific records where I need the ID and the Date to match, here is my code:

      $testq= DB::table('attendances')->where('user_id', '=', $userinput && 'logon', '=', $newdate)->get();

2 Answers 2

8

Just add one more where.

$testq= DB::table('attendances')
    ->where('user_id', '=', $userinput)
    ->where('logon', '=', $newdate)
    ->get();

http://laravel.com/api/4.2/Illuminate/Database/Eloquent/Builder.html#method_where

$this where(string $column, string $operator = null, mixed $value = null, string $boolean = 'and')

Add a basic where clause to the query.

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

8 Comments

excuse me for asking you one more, but can you tell me how to use if statement and determine if the record exist? 'if($testq exists)' ?
@jakebalba, you could check $testq->count() laravel.com/api/4.2/Illuminate/Database/Eloquent/…
so it will be like this ? 'if ($testq->count()<1)' sorry newbie here
@jakebalba, you have wrote the code - do not ask - test it. Test takes less time than asking : )
@jakebalba, add one more question with your code and attemps
|
5

As an addition to @sectus's answer, you might like this syntax:

$testq= DB::table('attendances')->whereUserId($userinput)
                                ->whereLogon($newdate)
                                ->get();

Comments

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.