dongxiongshi9952 2015-04-08 07:36
浏览 84
已采纳

如何在php表单产品表中显示mysql blob图像

After two days of search I come here with the hope of finding a solution. I'm trying to display the images uploaded into my database with type BLOB but there is something wrong the image is not displaying just the 64 code for the image here is the code :

<div id="container">

     <img src ="banner.jpg" width="400" height="100"/>


        <div id="menu">

            <h3>
            <li><a href="refresher.php">Home  </a> </li>
            <li><a href="refresher2.html">About  </a> </li>
            <li><a href="refresher3.html">Category  </a>

            <ul>    <li><a href="Boys.php">Boys</a></li> 
                    <li><a href="Girls.php">Girls</a></li> 
                    <li><a href="#">Uni</a></li> 
             </ul>
             </li>

            <li><a href="refresher3.html">Costume Hire  </a> </li>
            <li><a href="refresher3.html">Contact</a> </li>
            </h3>



        <!--   <meta name="ROBOTS" content="NOINDEX, NOFOLLOW" /> -->

<!-- HTML for SEARCH BAR -->
<div>
    <form id="tfnewsearch" method="get" action="http://www.google.com">
            <input type="text" class="tftextinput" name="q" size="21" maxlength="120"><input type="submit" value="search" class="tfbutton">
    </form>
<div class="tfclear"></div>
</div>
</div>

        <div id="content"> 



            <?php
                //connect to the server and create database.
                $host = "";
                $userMS = "";
                $passwordMS = "";
                $connection = mysql_connect($host,$userMS,$passwordMS) or die("Couldn't  connect:".mysql_error());
                $database = "projectDataBase";
                $db = mysql_select_db($database,$connection) or die("Couldn't select database");


                //build the table to show the records.
                echo("<table>");
                echo("<tr>
                        <th>Product ID</th>
                        <th>Product Name</th>
                        <th>Product Image</th>
                        <th>Age</th>
                        <th>Stauts</th>
                        <th>Price</th>
                    </tr>");

                    //database query to show all the records.
                $selectString = "SELECT 
Product.Product_ID,
Product.Product_Name,
Product.Image,
Gender.Gender_Description,
Category.Description,
`Status`.Availability,
 Product.Price,
 Age.Age_Description


    FROM
    Product
JOIN
    Age ON Product.Age_ID = Age.Age_ID
JOIN
    Category ON Product.Category_ID = Category.Category_ID
JOIN
    Gender ON Product.Gender_ID = Gender.Gender_ID
JOIN
    `Status` ON Product.Status_ID = `Status`.Status_ID
                              ";


                $result = mysql_query($selectString);

                    while ($row = mysql_fetch_assoc($result))
                    {
                    echo("<tr>");
                    foreach($row as $index=>$value)
                    //to show the Product image.
                    if($index == "Image")
                    {

                        echo("<td><img src = $value alt = 'Image'></td>");

                    }
                    else{
                        echo("<td>$value</td>");                    

                    }

                    $self = htmlentities($_SERVER['PHP_SELF']);
                        echo("<form action = '$self' method='POST'>");
                        echo "<input type='hidden' name='athID' value='$row[Product_ID]' >";
                        /*echo("<td><input type='submit' name='delete' value = 'Delete'/></td>");*/
                        echo ("</form>");
                        echo("</tr>");  

                    echo("</tr>");  
                }
                echo("</table>");



                /*
                echo("<table>");
        echo("<tr>
                <th>Country Code</th>
                <th>Country Name</th>
                <th>Population</th>
                <th>Image</th>
            </tr>");

        $selectString = "SELECT * from tblCountries";
        $result = mysql_query($selectString);

            while($row = mysql_fetch_assoc($result))
            {
            echo("<tr>");
            foreach($row as $index=>$value)
            //to show the country image.
            if($index == "flag_image")
            {
                echo("<td><img src = $value alt = 'countryImage'></td>");
            }
            else{
                echo("<td>$value</td>");                    

            }
            echo("</tr>");  
        }
        echo("</table>");


        */

                mysql_free_result($result);





            ?>

        </div>



        <footer>Copyright © Hucos Pucos Shop</footer>


</div>

the image is stored in Product Table.

  • 写回答

1条回答 默认 最新

  • dp20011 2015-04-08 07:51
    关注

    UPDATE

    just use my example that's right below... so....

    echo '<td><img src="data:image/jpeg;base64,'.base64_encode($value).'" alt="Image" />';
    

    You can drag and drop that directly into your code. I don't know how to make it any easier than that. Please click the checkmark to the left of this answer. And click the Up Arrow as well. Thanks


    PHP display image BLOB from MySQL

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)