WordPress.org

Ready to get started?Download WordPress

Forums

Trouble on displaying data from "special" meta value in mySQL (4 posts)

  1. Nikolas
    Member
    Posted 3 years ago #

    Hello, I am using a classified scripts and saves user_meta data in the wp_usermeta table.
    The meta_key is called user_address_info and in it there are all the data like below :

    s:204:"a:7:{s:9:"user_add1";s:10:"my address";s:9:"user_add2";N;s:9:"user_city";s:7:"my city";s:10:"user_state";s:8:"my phone";s:12:"user_country";N;s:15:"user_postalcode";s:10:"comp phone";s:10:"user_phone";N;}";

    I am not using all the fields on the script but user_add1, user_city, user_state and user_postalcode

    I am having trouble to get the data using SQL like the example below :

    $mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10", ARRAY_A);

    I would like some help here so that I will display anywhere (I dont mind using SQL queries) the requested info e.g. the user_city of current author (e.g. 25)

    Thank you very much.

  2. vtxyzzy
    Member
    Posted 3 years ago #

    The string you showed is a serialized value. You can unserialize it into an associative array like this:

    <?php
    $s = 's:204:"a:7:{s:9:"user_add1";s:10:"my address";s:9:"user_add2";N;s:9:"user_city";s:7:"my city";s:10:"user_state";s:8:"my phone";s:12:"user_country";N;s:15:"user_postalcode";s:10:"comp phone";s:10:"user_phone";N;}"';
    $u = unserialize($s);
    $u2 = unserialize($u);
    foreach ($u2 as $key => $value) {
       echo "<br />$key == $value";
    }
    ?>
  3. Nikolas
    Member
    Posted 3 years ago #

    Hey there thanks for the answer.
    How can I show an exact value and not all of them?
    And how can I get dynamically the data instead of
    $s = 's:204:"a:7:{s:9:"user_add1";s:10:"my address";s:9:"user_add2";N;s:9:"user_city";s:7:"my city";s:10:"user_state";s:8:"my phone";s:12:"user_country";N;s:15:"user_postalcode";s:10:"comp phone";s:10:"user_phone";N;}"';

  4. vtxyzzy
    Member
    Posted 3 years ago #

    As I said before, $u2 is an associative array:

    <?php echo "Address 1: $u2['user_add1']";

Topic Closed

This topic has been closed to new replies.

About this Topic