简体   繁体   中英

How to display BLOB Images from database in a while loop

I've been working on these codes for 2 hours now and i can't seem to make it appear. It has the right ID, but the picture doesnt show. i have no idea why.

anyway, here are my codes.

this is for showing the pic along with other stuff.

<div align="left">
<center><img src="img/compressportbanner.jpg" height="180"></center>
    <table border="0" cellpadding="2px" width="600px">
        <?php

            $result=mysql_query("select * from inventory WHERE prod_brand = 'Compressport' AND prod_category='compression' ");
            while($row=mysql_fetch_array($result)){
        ?>
        <tr>
            <td>    

            <?php 
            echo '<'.'img src="image.php?prod_id='.$row['prod_id'].'" alt="'.$row['prod_name'].'" width="250">'; 

            ?> 
            </td>
            <td>    <b><?php echo $row['prod_name']?></b><br />
                    <?php echo $row['prod_category']?>
                    <!--<?php echo $row['prod_desc']?>-->
                    <br>
                    Price:<big style="color:green">
                        ₱ <?php echo $row['prod_price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?php echo $row['prod_id']?>)" />

            </td>
        </tr>
        <tr><td colspan="2"><hr size="1" /></td>
        <?php } ?>
    </table>
</div>

and here is the image.php

<?php
$prodID=($_GET['prod_id']);
$sql = "SELECT * FROM `inventory` where `prod_id` = ".$prodID;
$qry = mysql_query($sql);
$result=mysql_fetch_array($qry);

echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['prod_pic'] ).'"/>'


?>

How do i make it appear, im new to php and im just starting to understand it.

Here's what I did with your codes, i added this line of code.

<?php echo '<img src="data:image/jpeg;base64,'.base64_encode($row['prod_pic']).'" width="250">';?> 

Here are the full codes.

<div align="left">
<center><img src="img/compressportbanner.jpg" height="180"></center>
    <table border="0" cellpadding="2px" width="600px">
        <?php

            $result=mysql_query("select * from inventory WHERE prod_brand = 'Compressport' AND prod_category='compression' ");
            while($row=mysql_fetch_array($result)){
        ?>
        <tr>
            <td>    

            <?php 

            echo '<img src="data:image/jpeg;base64,'.base64_encode($row['prod_pic']).'" width="250">';

            ?> 
            </td>
            <td>    <b><?php echo $row['prod_name']?></b><br />
                    <?php echo $row['prod_category']?>
                    <!--<?php echo $row['prod_desc']?>-->
                    <br>
                    Price:<big style="color:green">
                        ₱ <?php echo $row['prod_price']?></big><br /><br />
                    <input type="button" value="Add to Cart" onclick="addtocart(<?php echo $row['prod_id']?>)" />

            </td>
        </tr>
        <tr><td colspan="2"><hr size="1" /></td>
        <?php } ?>
    </table>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM