I'm having a hard time fetching the image from the database. I can only fetch the id of the image but the actual image file cannot. this my code in display.php where im trying to fetch the image.
$sql="Select * from tblcenter";
$result=mysqli_query($con,$sql);
$number=1;
while($row=mysqli_fetch_assoc($result)){
$id=$row['id'];
$img_id = $row['img_id'];
$name=$row['name'];
$mobile=$row['mobile'];
$email=$row['email'];
$address=$row['address'];
$table.='
<tr>
<td scope="row">'.$number.'</th>
<td><img src = "data:uploads/;base64,'.base64_encode($row['img_id']).'"style="width: 100px;
height: 100px"></td>
<td>'.$name.'</td>
<td>'.$mobile.'</td>
<td>'.$email.'</td>
<td>'.$address.'</td>
<td>
<button onclick="GetDetails('.$id.')">Update</button>
<button onclick="DeleteUser('.$id.')">Delete</button>
</td>
</tr>';
$number ;
}
this is the result of my current code
this the database/table of image
CodePudding user response:
$sql="Select t.*,i.img_name from tblcenter t JOIN images i ON t.img_id = i.id";
$result=mysqli_query($con,$sql);
$number=1;
while($row=mysqli_fetch_assoc($result)){
$id=$row['id'];
$img_name = $row['img_name'];
$name=$row['name'];
$mobile=$row['mobile'];
$email=$row['email'];
$address=$row['address'];
$table.='
<tr>
<td scope="row">'.$number.'</th>
<td><img src = "/images/'. $row['img_name'] . '" style="width: 100px;
height: 100px"></td>