dongzhuo3059 2018-12-05 21:47
浏览 42

使用MAMP从MySQL数据库显示图像[重复]

I'm trying to query images from a MySQL Database through MAMP on MacOS.

I'm using this code:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- <meta name="viewport" content="width=device-width, intial-scale=1.0"/> -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<title>Show Image in PHP</title>
<style>
    body{background-color: #f2f2f2; color: #333;}
    .main{box-shadow: 0 .125rem .25rem rgba(0,0,0,.075)!important; margin-top: 10px;}
    h3{background-color: #4294D1; color: #f7f7f7; padding: 15px; border-radius: 4px; box-shadow: 0 1px 6px rgba(57,73,76,0.35);}
    .img-box{margin-top: 20px;}
    .img-block{float: left; margin-right: 5px; text-align: center;}
    p{margin-top: 0;}
    img{width: 375px; min-height: 250px; margin-bottom: 10px; box-shadow: 0 .125rem .25rem rgba(0,0,0,.075)!important; border:6px solid #f7f7f7;}
</style>
</head>
    <body>
    <!-------------------Main Content------------------------------>
    <div class="container main">
        <h3>Showing Images</h3>
        <div class="img-box">
    <?php

        $username="root"; $password="root"; $database="SomeImages";

        $con = mysqli_init();
        mysqli_options($con, MYSQLI_OPT_LOCAL_INFILE, true);
        mysqli_real_connect($con, "localhost", $username, $password, $database);

        mysqli_select_db($database);

        $image_query = mysqli_query($con, "SELECT framing,im FROM images");


        while($rows = mysqli_fetch_array($image_query))
        {
            $img_name = $rows['framing'];
            $img_src = $rows['im'];
        ?>

        <div class="img-block">
        <img src="<?php echo $img_src; ?>" alt="" title="<?php echo $img_name; ?>" width="300" height="200" class="img-responsive" />
        <p><strong><?php echo $img_name; ?></strong></p>
        </div>

        <?php
        }
    ?>
        </div>
    </div>
    </body>
</body>
</html>

When I "run" it from my IDE (CodeRunner), I get totally functional html in the console (and no error messages), like this:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- <meta name="viewport" content="width=device-width, intial-scale=1.0"/> -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<title>Show Image in PHP - Campuslife</title>
<style>
    body{background-color: #f2f2f2; color: #333;}
    .main{box-shadow: 0 .125rem .25rem rgba(0,0,0,.075)!important; margin-top: 10px;}
    h3{background-color: #4294D1; color: #f7f7f7; padding: 15px; border-radius: 4px; box-shadow: 0 1px 6px rgba(57,73,76,0.35);}
    .img-box{margin-top: 20px;}
    .img-block{float: left; margin-right: 5px; text-align: center;}
    p{margin-top: 0;}
    img{width: 375px; min-height: 250px; margin-bottom: 10px; box-shadow: 0 .125rem .25rem rgba(0,0,0,.075)!important; border:6px solid #f7f7f7;}
</style>
</head>
    <body>
    <!-------------------Main Content------------------------------>
    <div class="container main">
        <h3>Showing Images from database</h3>
        <div class="img-box">

Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in index.html on line 31

        <div class="img-block">
        <img src="images/0.jpg" alt="" title="3" width="300" height="200" class="img-responsive" />
        <p><strong>3</strong></p>
        </div>


        <div class="img-block">
        <img src="images/2.jpg" alt="" title="3" width="300" height="200" class="img-responsive" />
        <p><strong>3</strong></p>
        </div>


        <div class="img-block">
        <img src="images/2.jpg" alt="" title="3" width="300" height="200" class="img-responsive" />
        <p><strong>3</strong></p>
        </div>
</div>
    </div>
    </body>
</body>
</html>

However, when I open the html/php code from a browser with http://localhost:8888/SomeImages/, I get this, where the php part in commented:

enter image description here

What am I doing wrong?

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 通过下面文章的方法求手机号段
    • ¥15 有偿求码,CNN+LSTM实现单通道脑电信号EEG的睡眠分期评估
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
    • ¥20 matlab yalmip kkt 双层优化问题
    • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体