• Hi this is probably pretty basic but I have just hit a stumbling block …

    I am currently storing data in the postmeta table and am trying to pull some results on the status of a new subscriber.

    The data in the postmeta table is stored as meta_key=userdata meta_value=”a:12:{a:12:{s:9:”firstname”;s:11:”TestContrib”;s:8:”lastname”;s:0:””;s:8:”cpcounty”;s:7:”Alameda”;s:7:”cpphone”;s:0:””;s:5:”ctype”;s:0:””;s:8:”caddress”;s:0:””;s:5:”ccity”;s:0:””;s:4:”czip”;s:0:””;s:11:”cited”;s:2:”No”;s:6:”cstage”;s:7:”welcome”;s:6:”cnotes”;s:0:””;s:5:”_meta”;a:5:{s:2:”ip”;s:14:”75.136.106.212″;s:8:”signupip”;s:14:”75.136.106.212″;s:10:”signuptime”;s:10:”1368150548″;s:9:”confirmip”;s:14:”75.136.106.212″;s:11:”confirmtime”;s:10:”1368150548″;}}”

    On my page I am executing the following code:

    global $wpdb;
    $results = $wpdb->get_results( "SELECT $wpdb->postmeta.meta_value FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'userdata'" );
    $options = array();
    foreach ($results as $result) {
    $options[$result->meta_value] = ucwords( $result->meta_value );
    }
    foreach ($options as $key => $value) {
    
    // echo back the current stage the users are in line by line.
    
    echo $key."  ".$value."<hr />";
    }

    This is currently pulling up and printing the entire serialized string within the database for each matched row of data. 1 for $key and 1 for $value they are the same (see below).
    a:12:{s:9:”firstname”;s:11:”TestContrib”;s:8:”lastname”;s:0:””;s:8:”cpcounty”;s:7:”Alameda”;s:7:”cpphone”;s:0:””;s:5:”ctype”;s:0:””;s:8:”caddress”;s:0:””;s:5:”ccity”;s:0:””;s:4:”czip”;s:0:””;s:11:”cited”;s:2:”No”;s:6:”cstage”;s:7:”welcome”;s:6:”cnotes”;s:0:””;s:5:”_meta”;a:5:{s:2:”ip”;s:14:”75.136.106.212″;s:8:”signupip”;s:14:”75.136.106.212″;s:10:”signuptime”;s:10:”1368150548″;s:9:”confirmip”;s:14:”75.136.106.212″;s:11:”confirmtime”;s:10:”1368150548″;}}
    A:12:{s:9:”firstname”;s:11:”TestContrib”;s:8:”lastname”;s:0:””;s:8:”cpcounty”;s:7:”Alameda”;s:7:”cpphone”;s:0:””;s:5:”ctype”;s:0:””;s:8:”caddress”;s:0:””;s:5:”ccity”;s:0:””;s:4:”czip”;s:0:””;s:11:”cited”;s:2:”No”;s:6:”cstage”;s:7:”welcome”;s:6:”cnotes”;s:0:””;s:5:”_meta”;a:5:{s:2:”ip”;s:14:”75.136.106.212″;s:8:”signupip”;s:14:”75.136.106.212″;s:10:”signuptime”;s:10:”1368150548″;s:9:”confirmip”;s:14:”75.136.106.212″;s:11:”confirmtime”;s:10:”1368150548″;}}

    I am trying to just pull the value for ‘cstage’ for a single or each entry in the table or any other single value or perhaps multiple values later but I just cant figure this out..Thank you in advance for your assistance.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘postmeta & array’ is closed to new replies.