I am trying to display one of three images in a table cell based on a field in my database.
I have created the following function
function chooseImage($imagetype)
{
global $connection;
$sql = "select * from uploads";
$result = $connection->query($sql) or die(mysqli_error($connection));
$numRows = $result->num_rows;
while($row = $result->fetch_assoc()) { // opening while loop bracket tag flag 2
$TypeOfFile = $row['document_type'];
if($TypeOfFile == 'PDF'){
$imagetype = "Adobe_Acrobat.png";
}elseif($TypeOfFile == 'JPG'){
$imagetype = "jpg.png";
}elseif($TypeOfFile == 'WORD') {
$imagetype = "iconBG4.gif";
}
}
return $imagetype;
}
which I call as follows
$file_type = chooseImage($imagetype);
<td>
<img src="images/<?php echo $file_type; ?>" alt="">
<td>
However the same image is displaying even though the database field contains WORD of JPG.
I suspect it is being caused by the way I am returning the variable within the function.
Best regards Maxwell