图像无法在php中显示

时间:2018-04-28 16:05:11

标签: php html

我正在开发一个网页项目并使用php来显示计算机的信息。我将图像的网址存储在一个关系中,并可以使用php成功检索它们。但它们无法在网页中显示。这是我的代码:

<?php
require_once('db_setup_hetty.php');
$sql = "USE hzhu24;";
if ($conn->query($sql) === TRUE){
   //echo "using Database hzhu24"
}else{
   echo "Error using database:" . $conn->error;
}
$C1 = $_POST["C1"];
$C2 = $_POST["C2"];
$query = "SELECT * FROM Items where Category1 Like '%$C1%' and Category2 Like '%$C2%';";
$result = $conn->query($query);

if($result->num_rows > 0){
?>

<?php
while($row = $result->fetch_assoc()){
$url = $row['Pic_url'];
?>
        <div class="col-sm-4">
                <div class="thumbnail">
                        <!--span class="e-label"><div>Sale</div></span-->
                        <span class="service-link text-center">
                                <img src= $url>
                                <div class="list-inline">
                                        <a href=""><i class="fa fa-eye"></i></a>
                                        <a href=""><i class="fa fa-link"></i></a>
                                </div>
                        </span>
                        <div class="caption">
                                <div class="category"> <?php echo $C2; ?>
                                        <div class="pull-right">
                                                <i class="fa fa-star"></i>
                                                <i class="fa fa-star"></i>
                                                <i class="fa fa-star"></i>
                                                <i class="fa fa-star"></i>
                                                <i class="fa fa-star-o"></i>
                                        </div>
                                </div>
                                <h3><?php echo $row['Item_name']; ?></h3>
                                <h4><?php echo $row['Brand']; ?></h4>
                                <!--strong>$899.00</strong-->
                                <div><a href="product-detail.html" class="btn btn-default" role="button">Details</a></div>
                        </div>
                </div>
        </div>
<?php
}
}
else {
echo "Item not found";
}
echo "</table>"
?>

网页看起来像: enter image description here

1 个答案:

答案 0 :(得分:0)

如果你的php版本&gt; = 5.4,你可以像这样使用短回声标记:

<?php
require_once('db_setup_hetty.php');
$sql = "USE hzhu24;";
if ($conn->query($sql) === TRUE){
   //echo "using Database hzhu24"
}else{
   echo "Error using database:" . $conn->error;
}
$C1 = $_POST["C1"];
$C2 = $_POST["C2"];
$query = "SELECT * FROM Items where Category1 Like '%$C1%' and Category2 Like '%$C2%';";
$result = $conn->query($query);

if($result->num_rows > 0){
?>
<?php
while($row = $result->fetch_assoc()){
$url = $row['Pic_url'];
?>
        <div class="col-sm-4">
            <div class="thumbnail">
                <!--span class="e-label"><div>Sale</div></span-->
                <span class="service-link text-center">
                                <img src=<?=$url;?>>
                                <div class="list-inline">
                                        <a href=""><i class="fa fa-eye"></i></a>
                                        <a href=""><i class="fa fa-link"></i></a>
                                </div>
                        </span>
                <div class="caption">
                    <div class="category">
                        <?=$C2;?>
                        <div class="pull-right">
                            <i class="fa fa-star"></i>
                            <i class="fa fa-star"></i>
                            <i class="fa fa-star"></i>
                            <i class="fa fa-star"></i>
                            <i class="fa fa-star-o"></i>
                        </div>
                    </div>
                    <h3><?=$row['Item_name'];?></h3>
                    <h4><?=$row['Brand'];?></h4>
                    <!--strong>$899.00</strong-->
                    <div><a href="product-detail.html" class="btn btn-default" role="button">Details</a></div>
                </div>
            </div>
        </div>
        <?php
}
}
else {
echo "Item not found";
}
echo "</table>"