I'm trying to figure out why my query isn't running, and if it is; why isn't it returning any info. I'm running this query on wordpress multisite based on a plugging that goes through all network sites and retrieves all posts in the main site, that part is working fine. I created a bit of code to merge two variables into one variable to create a table name, if I echo that variable it displays the table name correctly, but when i insert the same variable in the query noting happens even dough the table already exists in the DB. the code is below:
// Switch to the blog
switch_to_blog($all_blogkeys[$field->guid]);
global $wpdb;
$prefix = $wpdb->prefix; //get current site table prefix
$table = 'rex_listings'; // name to attach to prefix
$tablename = $prefix.''.$table; // combine prefix and name
//start the query and echo results
$result = $wpdb->get_results('SELECT price, bedrooms, baths, floor_space, formatted_address FROM $tablename');
foreach($result as $row) {
echo 'Price: '.$row->price.', Bedrooms: '.$row->bedrooms.', Baths: '.$row->baths.', Floor Space: '.$row->floor_space.', Address: '.$row->formatted_address.',<br/>';}
Thanks in advance.