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

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];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.