What you're seeing there is an array of objects (within only a single item in that array).
$obj = $array[0]; // Change the $array to match your variable name
echo $obj->location_id;
echo $obj->location_name;
Alternatively, you can update get_results()
to return the items as an array of arrays.
For example:
$query = "SELECT * FROM $wpdb->posts"; // Change to suit your needs
$array = $wpdb->get_results( $query, ARRAY_A );
$arr = $array[0]; // Change the $array to match your variable name
echo $arr['location_id'];
echo $arr['location_name'];
Typically, you would use get_results()
to get multiple rows, so you would use foreach()
or something similar:
$results = $wpdb->get_results( $query, ARRAY_A );
foreach ($results as $row) {
echo $row['location_id'];
echo $row['location_name'];
}
If you only wanted to get a single row, you can use the get_row($query, ARRAY_A)
method instead.
There's lot of information about the $wpdb
class in the WordPress Codex.