WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Editing the object returned by $wpdb->get_results(SQL) (3 posts)

  1. Mads Phikamphon
    Member
    Posted 1 year ago #

    Hi,

    We have a nasty database call using $wpdb->get_results(SQL).

    After receiving the result in PHP, we need to make a few changes to the result.

    So can anyone tell me how I can:
    1) Remove specific rows from the returned object.
    2) Change the values of the specific columns in specific rows in the returned object.

    I.e. if the object returned is $nastyData, we need to:
    1) Remove specific rows from $nastyData
    2) Change the value of specific columns in specific rows in $nastyData, for example $nastyData->name for a specific row.

    Any ideas?

    I have thought about makeing get_results() return the data as an array, but that will create problems in other places in our code (where the code expects to receive an object).

    Thanks,
    Mads

  2. bcworkz
    Member
    Posted 1 year ago #

    An object is very much like an associative array. You can remove rows with unset $nastyData[$row]; and you can change certain column values with $nastyData[$row]->column_name = $new_value; where $row is the index number of the object row.

  3. Mads Phikamphon
    Member
    Posted 1 year ago #

    Excellent. Thanks a lot, it helped make everything work properly :)

Topic Closed

This topic has been closed to new replies.

About this Topic