I have a MySQL query that is not working and I'm not sure why.
Here is my code for selecting the id from the url and using it as a variable so Mysql can return the img_url column.
<?php
global $wpdb;
$table_name = $wpdb->prefix . "photos";
$url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$id = basename(parse_url($url, PHP_URL_PATH));
$image = $wpdb->get_results("SELECT img_url FROM $table_name WHERE id = $id");
echo $id
?>
and then to show my image
<img src='<?php echo $image; ?>'>
The result I get back from MySQL is "array". I don't know if it matters but the id column is AUTO_INCREMENT PRIMARY KEY. Also, I know "echo $id" does return the the id from the url so I know it works. Any suggestions? Thanks.
$image = $wpdb->get_var("...")wpdb::get_var