1

I have:

$value = $wpdb->get_row("SELECT custom_message FROM `wp_wpsc_cart_contents` WHERE purchaseid='" . $purchase_log['id'] . "'");

if I do:

print_r($value);

I get:

stdClass Object
(
    [custom_message] =>  |Castor Seed Oil  $4.45| 
)

So I tried to get that value doing:

foreach($value as $index => $result) {
   echo $result["custom_message"];
}

I also tried:

foreach($value as $index => $result) {
   echo $result->custom_message;
}

but that prints nothing, any idea what I'm doing wrong here?

2 Answers 2

2

The loop does nothing, you are iterating an object with a single property that you already know the name of. Just do this:

echo $value->custom_message;
Sign up to request clarification or add additional context in comments.

Comments

1

No need for the for loop. Just do

  echo $value->custom_message;

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.