• 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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    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.

    Thread Starter Mads Phikamphon

    (@madsphi)

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Editing the object returned by $wpdb->get_results(SQL)’ is closed to new replies.