0

Here is what I have so far:

function get_highest_bid_info(){
    global $wpdb;
    $postid = get_the_id();
    $table = $wpdb->prefix . "jwp_bids";
    $wpdb->get_results(
        "SELECT email, max(bid_amt)
        FROM  $table
        WHERE post_id = '$postid')"
        );

Now I want to assign those two values to independent variables such as $high_bid and $high_bidder. I know the two values are in an array of some sort. I read in the codex but don't ascertain from that How to access and assign them?

Any help is greatly appreciated. I'm learning here :)

Thanks!

2 Answers 2

0

Best luck while you learn.

$fivesdrafts = $wpdb->get_results( 
    "
    SELECT ID, post_title 
    FROM $wpdb->posts
    WHERE post_status = 'draft' 
        AND post_author = 5
    "
);

foreach ( $fivesdrafts as $fivesdraft ) 
{
    echo $fivesdraft->post_title;
}

This example has been sponsored by WordPress codex.


In your case

$wpdb->get_results(

Should become like:

$variable_to_print = $wpdb->get_results(
2
  • Thanks but doesn't that assign both values ( email, bid_amount) to one variable?? I need to assign email to a variable and bid_amount to another variable.
    – James
    Commented Jan 8, 2017 at 3:10
  • Hi @James, it is not good to interfere further at the moment. You must grind the food yourself.
    – prosti
    Commented Jan 8, 2017 at 8:25
0

This is what worked:

function find_highest_bid(){
    global $wpdb;
    $postid = get_the_id();
    $table = $wpdb->prefix . "jwp_bids";
    $highest_bid = $wpdb->get_results(
        "Select max(bid_amt) AS bid, bid_time, email
        FROM $table
        WHERE post_id = '1277'", ARRAY_A );
    $highest_bid = array_shift ( $highest_bid );
    $high_bid = $highest_bid['bid'];
    $high_bidder = $highest_bid['email'];
    $bid_time = $highest_bid['bid_time'];
    echo '$'. $high_bid;
    echo ", ";
    echo $high_bidder;
    echo ", ";
    echo $bid_time;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.