I have a loop which loops through various rota (staff lists) for each day day of the week as part of that loop I have the following code that I want to use to pull the filename of an image out of my database to display a users photo.
The function:
// FETCH MAIN PHOTO FOR USER
function mainUserPhoto_byname($user_name){
require 'includes/db.config.php';
$query = "SELECT
mainphoto_file
FROM media_mainphotos WHERE user_name = '$user_name'
";
try
{
$stmt = $conn->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$display_main_photo = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $display_main_photo;
}
The line of code I want to populate with the filename value (note I have left the echo as var_dump but obviously want to replace that with just the filename portion on the array:
<?php $main_photo = mainUserPhoto_byname($rota_sunday['user_name']); ?>
<p style="font-size: 13px !important;">[img]<?php echo var_dump($main_photo); ?>[/img]</p>
The var_dump shows the correct values do exist in the array:
array(1) { [0]=> array(1) { ["mainphoto_file"]=> string(61) "30132-nina-04.jpg" } }
No matter what I try I can not get the filename to echo properly - I either get an undefined index error or simply the word Array
.