WordPress: Trying to fetch one row of data and set into array -


i'm trying use wordpress built-in functions search , retrieve 1 row of data , place in string, "object of class stdclass not converted string.." error. code i'm using is:

<?php $zip = $_get['z']; //primary key $zip    global $wpdb; $results = $wpdb->get_results("select * wp_main_placename_zip _zip_code = $zip");  $array = json_decode(json_encode($results), true);  echo $array[0]; echo $array[1]; echo $array[2]; //echo $results[1]; //echo $results[2]; ?> 

thanks in advance!

the object printing object, in case

$array[0];
return object.. example

error : http://codepad.org/igbzcn6w

$code = '[{"id":2,"name":"bob"},{"id":3,"name":"maria"}]'; $parse = json_decode($code);  //"object of class stdclass not converted string.. echo $parse[0];  //prints bob echo $parse[0]->name 

if want print entire object can use print_r or var_dump

//prints object echo var_dump($parse[0]); 

check if http://codepad.org/ewiubniu

revised code

$zip = $_get['z']; //primary key $zip    global $wpdb; $results = $wpdb->get_results("select * wp_main_placename_zip _zip_code = $zip");  $array = json_decode(json_encode($results));  //_zip_code field echo $array[0]->_zip_code; // or fields var_dump($array[1]); 

i hope i've helped :)


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -