0

My field in table is an array and I want to convert it to an int.

$totalreward = DB::table('bid_packs')
    ->select('bid_pack_reward_points')->first();
$solve = $totalreward * $qty;

print_r ($solve);

It always prompt this error

Object of class stdClass could not be converted to int

2
  • What are the fields in your tables? Commented Jul 16, 2015 at 6:05
  • its too many but i want to select the bid_pack_reward_points for computing the qty Commented Jul 16, 2015 at 6:41

1 Answer 1

1

DB::table('bid_packs')->select('bid_pack_reward_points')->first(); returns an object that has properties with the names of the fields you selected.

In this case:

$totalreward = DB::table('bid_packs')->select('bid_pack_reward_points')->first();
$solve = $totalreward->bid_pack_reward_points * $qty;
print_r ($solve);

Or, since you're trying to get one value from the first row, you can use pluck() to get straight to the value:

$totalreward = DB::table('bid_packs')->pluck('bid_pack_reward_points');
$solve = $totalreward * $qty;
print_r ($solve);
Sign up to request clarification or add additional context in comments.

4 Comments

@KouyaMarino No problem. I notice you're a new user, so don't forget to mark this as the answer if it solved your problem. This helps maintain the integrity of the site.
sorry im just newbie in stackoverflow :)
@KouyaMarino We all were at some point. :) But, that's the reason for the comment, just to help others help contribute to the community. You get the hang of it after a while.
but theres some problem . :( i post the problem below i hope you can help me :/ thanks

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.