0

How can I fetch the object from the array; I'm getting this data from the query.

I query this table:

DB::select("SELECT * FROM verified_data where target_id=3");

and getting this result:

array(124) {
  [0]=>
  object(stdClass)#445 (8) {
    ["id"]=>
    int(83)
    ["user_id"]=>
    int(0)
    ["target_id"]=>
    int(3)
    ["target_type"]=>
    string(6) "assets"
    ["user_comments"]=>
    string(13) "Well and good"
    ["created_at"]=>
    string(19) "2016-08-11 18:35:39"
    ["updated_at"]=>
    string(19) "2016-08-11 18:35:39"
    ["is_verified"]=>
    int(1)
  }
  [1]=>
  object(stdClass)#446 (8) {
    ["id"]=>
    int(84)
    ["user_id"]=>
    int(0)
    ["target_id"]=>
    int(3)
    ["target_type"]=>
    string(6) "assets"
    ["user_comments"]=>
    string(13) "Well and good"
    ["created_at"]=>
    string(19) "2016-08-11 18:48:07"
    ["updated_at"]=>
    string(19) "2016-08-11 18:48:07"
    ["is_verified"]=>
    int(1)
  }
  [2]=>
  object(stdClass)#447 (8) {
    ["id"]=>
    int(85)
    ["user_id"]=>
    int(0)
    ["target_id"]=>
    int(3)
    ["target_type"]=>
    string(6) "assets"
    ["user_comments"]=>
    string(13) "Well and good"
    ["created_at"]=>
    string(19) "2016-08-11 18:48:26"
    ["updated_at"]=>
    string(19) "2016-08-11 18:48:26"
    ["is_verified"]=>
    int(1)
  }

And I want the ["is_verified"] from the this data, how can I get this in a variable and then display it in my input value?

2 Answers 2

1

Is this what you're trying to do:

$data = DB::select("SELECT * FROM verified_data where target_id=3");

if ( !empty($data) && is_array($data) ) {
    foreach ( $data as $record ) {
        $record->is_verified; //TODO do something with this value
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

i just want the value which is stored in [is_verified] which should be 1 or 0 so how can i get this value and stored in variable??
0

If you want to retrieve all records and get is_verified field:

$data = DB::table('verified_data')->where('target_id', 3)->get('is_verified');

or:

$data = DB::table('verified_data')->select('is_verified')->get();

For a single row use:

$data = DB::table('verified_data')->where('target_id', 3)->first('is_verified');

or:

$data = DB::table('verified_data')->select('is_verified')->first();

More information in official documentation.

I hope, it might be helpful.

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.