0

Hi,

I am having a bit of trouble getting my fetch(PDO::FETCH_OBJ) to print the way I want. I am also unsure if fetch(PDO::FETCH_OBJ) is the right thing to use.

Code below.

$sqlTotal = "SELECT SUM(price) FROM `$user` WHERE `cart`=1";
	$total = $conn->query($sqlTotal);
	$total->execute();
	$totalResult = $total->fetch(PDO::FETCH_OBJ);
	$totalResult = print_r($totalResult);

It is printing out as: stdClass Object ( [SUM(offer)] => 58000 )
So the statement works.
But I only want '58000' to display or return.

How can I do this?

Thanks,

QWaz

1
Contributor
1
Reply
5
Views
7 Years
Discussion Span
Last Post by QWaz
0

Hi,

I am having a bit of trouble getting my fetch(PDO::FETCH_OBJ) to print the way I want. I am also unsure if fetch(PDO::FETCH_OBJ) is the right thing to use.

Code below.

$sqlTotal = "SELECT SUM(price) FROM `$user` WHERE `cart`=1";
	$total = $conn->query($sqlTotal);
	$total->execute();
	$totalResult = $total->fetch(PDO::FETCH_OBJ);
	$totalResult = print_r($totalResult);

It is printing out as: stdClass Object ( [SUM(offer)] => 58000 )
So the statement works.
But I only want '58000' to display or return.

How can I do this?

Thanks,

QWaz

ANSWER:

$sqlTotal = "SELECT SUM(price) FROM `$user` WHERE `cart`=1";
	$total = $conn->query($sqlTotal);
	$total->execute();
	$totalResult = $total->fetch(PDO::FETCH_NUM);
	$totalResult = $totalResult[0];
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.