gpt4 book ai didi

php - 如何从数据库中检索图像并在网页上显示图像

转载 作者:行者123 更新时间:2023-11-29 07:14:10 26 4
gpt4 key购买 nike

我已将图像插入数据库并将名称存储在表中。我的图像保存在名为“Uploads”的文件夹中。现在需要从数据库检索图像并显示它。当我尝试显示时,它仅显示从我的表中获取的图像名称。但它不显示图像。

下面给出了检索代码

$sql="SELECT * FROM candi_profile WHERE can_email='{$_SESSION['usr_email']}'";

$result=mysqli_query($con,$sql);
if(!$result) die(mysqli_error($con));
<div class="container">

<!-- Page Header -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Employer Dashboard

</h1>
</div>
</div>
<!-- /.row -->

<!-- Projects Row -->

<div class="row">
<div class="col-md-4">
<?php
while($rows=mysqli_fetch_array($result)){
$c_id = $rows['can_id'];
var_dump($c_id);
?>

<p class="lead"><?php echo $rows['can_name'] ?></p>
<div class="profile-sidebar">
<!-- SIDEBAR USERPIC -->

<div class="profile-userpic">
<p class="lead">
<?php echo $rows['pic_name'] ?></p>
</div>

<!-- END SIDEBAR USERPIC -->

<!-- SIDEBAR USER TITLE -->
<div class="profile-usertitle">
<div class="profile-usertitle-name">
Marcus Doe
</div>
<div class="profile-usertitle-job">
<?php echo $rows['can_city'] ?>
<i class="glyphicon glyphicon-map-marker">
</i>
</div>

<div class="profile-usertitle-job">
<i class="glyphicon glyphicon-envelope"></i>
<?php echo $rows['can_email'] ?>
</div>

<div class="profile-usertitle-job">
<?php echo $rows['can_country'] ?>
</div>
</div>
<!-- END SIDEBAR USER TITLE -->

<!-- SIDEBAR BUTTONS -->
<div class="profile-userbuttons">
<hr>
</div>

<!-- END SIDEBAR BUTTONS -->
<!-- SIDEBAR MENU -->

<?php
}
?>
</div>

enter image description here enter image description here

最佳答案

您可以使用此代码从数据库检索图像

<?php
include 'connection.php'
?>
<?php

$result = mysql_query("SELECT * FROM table") or die(mysql_error());


?>

<table border="1" cellpadding="5" cellspacing="5">
<tr> <th>Image</th></tr>

<?php

while($row = mysql_fetch_array($result)) {

$id = $row['id'];

?>
<tr>

<td><img src="uploads/<?php echo $row['pic_name'];?>" alt=" " height="75" width="75"></td>

</tr>

<?php
}
}

?>
</table>

关于php - 如何从数据库中检索图像并在网页上显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38560752/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com