0

I am attemping to calculate the cost by issuing the query below however it always return no value:

        //Re-calculate the cost price
        $f15 = "SELECT sum(cost) FROM ingredients WHERE item_id_fk = :targetID";
        $e16 = $this->l1->prepare($f15);
        $e16->bindParam(':targetID', $g4);
        $e16->execute();
        $g5 = $e16->fetch(PDO::FETCH_NUM);

        error_log(print_r($g5[0], TRUE));

Did I miss out something? Your help is kindly appreciated.

Thank You.

3
Contributors
6
Replies
31
Views
2 Years
Discussion Span
Last Post by diafol
0

Try to remove the WHERE condition, just to see if the query returns something and what is assigned to :targetID:

$f15 = "SELECT sum(cost), :targetID as 'target' FROM ingredients";

And in output do:

error_log(print_r($g5, TRUE));

So you get the full array.

1

Ok, but the $g4 value is sent to the query? And if you perform the original query directly into a mysql client, do you get results?

1

I'd var_dump( $g4 ) to see what you get. And as cereal says, hardcode the value into the SQL WHERE clause to see if you get anything returned.

Votes + Comments
+1
0

The solution is to access the value in the array by column name as follow:

$e16->bindParam(':targetID', $g4['itemId']);
0

Heh heh, of course it is. It was obvious that $g4 was an array! :rolleyes:
BTW - why all the short names? Don't you get confused?

This topic has been dead for over six months. 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.