Display blob in php from table

ionutp23

Registered User.
Local time
Yesterday, 22:43
Joined
Dec 23, 2019
Messages
30
Hi a friend made this code for me to display data from mysql table IMAGE TITLE AND LINK (title has link ) everything works ok except image wont show up as is uploaded to mysql as blob can you please help me fix it? my row where is image is ( channel_poster )

Code:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./css/bootstrap.css">
</head>
<style>
.cont-wrapper li img {
max-width: 100px;
height: 100px;
width: 100%;
object-fit: cover;
margin: 5px;
border: 2px solid #d55656;
border-radius: 5px;
}
.cont-wrapper li a {
    margin: 10px;
    color: #ccc;
    width: 100%;
transition: all .3s ease-in-out;
-webkit-transition: all .3s ease-in-out;
padding: 16px 0;
}
.cont-wrapper li a:hover {
color: #d55656;
text-decoration: none;
}
.col-list {
background-color: #3e3633cc;
border-radius: 5px;
}
.cont-wrapper li {
list-style: none;
border: 1px solid #ccc;
border-left: none;
border-right: none;
}
.cont-wrapper li:hover img {
    opacity: 0.8;
}
.cont-wrapper li:first-child  {
  border-top: none;
}
.cont-wrapper li:last-child  {
  border-bottom: none;
}

.cont-wrapper {
padding: 0;
}

@media screen and (max-width: 440px ) {
.cont-wrapper li img {
    max-width: 70px;
    height: 70px;
}
}


</style>
<body>
    <div class="myapp p-5">
        <div class="container">
              <div class="row">
                <div class="col-list col-md-12 col-sm-6 mb-3">
                  <ul class="cont-wrapper mt-3">

                  <?php			
                      require 'conn.php';
                      $query = mysqli_query($conn, "SELECT * FROM tv_channels");
                      while($fetch = mysqli_fetch_array( $query)){
                  ?>

                    <li  class="d-flex align-items-center">
                        <img src="/home/turbohdp/public_html/servicepc.net/images/<?php echo $fetch['channel_poster_title']?>" alt="" class="img-responsive">
                        <a href="<?php echo $fetch['channel_url']?>" target="_"><?php echo $fetch['channel_title']?> »</a>
                    </li>
                    <?php
					    }
                    ?>
                    
                  </ul>
                </div>
              </div> 
        </div>
    </div>
</body>
</html>
 
Last edited by a moderator:
Ionutp
As you can see I've added code tags (# button on toolbar) to make it easier to read.

Sorry I'm unable to assist as I know nothing about this area.
However, I've noticed that most of your posts are largely unrelated to Access and wonder whether a more specialist MySQL forum would be more suitable for your needs?

Good luck finding a solution
 
ion,

I think your code may be a little "spaghettified". this portion of it:
Code:
                    <li  class="d-flex align-items-center">
                        <img src="/home/turbohdp/public_html/servicepc.net/images/<?php echo $fetch['channel_poster_title']?>" alt="" class="img-responsive">
                        <a href="<?php echo $fetch['channel_url']?>" target="_"><?php echo $fetch['channel_title']?> »</a>
                    </li>
                    <?php
                        }
                    ?>
does not look right. are you even sure you can ECHO out a return from FETCH()? fetch is an asynchronous technology and it is an extension of javascript. as far as I know, it has nothing to do with PHP, although you CAN make it operate inside PHP tags, which you are doing already. the last bit looks redundant too, because you've only got one "}" brace inside php tags. that makes no sense. I've never stored images in a database like you're doing, but I do believe blob is the right type of field. If you got this from a friend that didn't explain anything about it to you, you should probably go back and ask him what it is "supposed" to do. Just getting code from someone who says it will work isn't guaranteed to work! too many variables involved between the environment they're in and the environment you're in. I hope this helps you. Let me know if you want more assistance and I might be able to expand on what I just said.
 
ion,

another thing I might able to offer you if you're still subscribed to this thread, is that I talked with a PHP veteran last week who told me that storing image files in a MYSQL database is bad practice and that if you want to display content dynamically on a webpage with an image, you should point to it in an actual directory on the server at runtime. (it looks like from your code though, that you are attempting to do that. I only mention this because you asked about the blob data type). Hope that helps!
 
ion,

another thing I might able to offer you if you're still subscribed to this thread, is that I talked with a PHP veteran last week who told me that storing image files in a MYSQL database is bad practice and that if you want to display content dynamically on a webpage with an image, you should point to it in an actual directory on the server at runtime. (it looks like from your code though, that you are attempting to do that. I only mention this because you asked about the blob data type). Hope that helps!

I got it fixed :D i need blob as in my pc program i use same image you can check here servicepc.net
 
ion,

I think your code may be a little "spaghettified". this portion of it:
Code:
                    <li  class="d-flex align-items-center">
                        <img src="/home/turbohdp/public_html/servicepc.net/images/<?php echo $fetch['channel_poster_title']?>" alt="" class="img-responsive">
                        <a href="<?php echo $fetch['channel_url']?>" target="_"><?php echo $fetch['channel_title']?> »</a>
                    </li>
                    <?php
                        }
                    ?>
does not look right. are you even sure you can ECHO out a return from FETCH()? fetch is an asynchronous technology and it is an extension of javascript. as far as I know, it has nothing to do with PHP, although you CAN make it operate inside PHP tags, which you are doing already. the last bit looks redundant too, because you've only got one "}" brace inside php tags. that makes no sense. I've never stored images in a database like you're doing, but I do believe blob is the right type of field. If you got this from a friend that didn't explain anything about it to you, you should probably go back and ask him what it is "supposed" to do. Just getting code from someone who says it will work isn't guaranteed to work! too many variables involved between the environment they're in and the environment you're in. I hope this helps you. Let me know if you want more assistance and I might be able to expand on what I just said.

PHP:
index.php


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./css/bootstrap.css">
</head>
<style>
.cont-wrapper li img {
max-width: 100px;
height: 100px;
width: 100%;
object-fit: cover;
margin: 5px;
border: 2px solid #d55656;
border-radius: 5px;
}
.cont-wrapper li a {
    margin: 10px;
    color: #ccc;
    width: 100%;
transition: all .3s ease-in-out;
-webkit-transition: all .3s ease-in-out;
padding: 16px 0;
}
.cont-wrapper li a:hover {
color: #d55656;
text-decoration: none;
}
.col-list {
background-color: #3e3633cc;
border-radius: 5px;
}
.cont-wrapper li {
list-style: none;
border: 1px solid #ccc;
border-left: none;
border-right: none;
}
.cont-wrapper li:hover img {
    opacity: 0.8;
}
.cont-wrapper li:first-child  {
  border-top: none;
}
.cont-wrapper li:last-child  {
  border-bottom: none;
}

.cont-wrapper {
padding: 0;
}

@media screen and (max-width: 440px ) {
.cont-wrapper li img {
    max-width: 70px;
    height: 70px;
}
}


</style>
<body>
    <div class="myapp p-5">
        <div class="container">
              <div class="row">
                <div class="col-list col-md-12 col-sm-6 mb-3">
                  <ul class="cont-wrapper mt-3">

                  <?php		
                      require 'conn.php';
                      $query = mysqli_query($conn, "SELECT * FROM `tbl_tvlink`");
                      while($fetch = mysqli_fetch_array( $query)){
                  ?>

                    <li  class="d-flex align-items-center">
                        <?php  echo '<img src="data:image/jpeg;base64,'.base64_encode( $fetch['tv_image'] ).'" >';?>
                        <a href="<?php echo $fetch['tv_link']?>" target="_blank"><?php echo $fetch['tv_title']?> »</a>
                    </li>
                    <?php
					    }
                    ?>
                    
                  </ul>
                </div>
              </div> 
        </div>
    </div>
</body>
</html>
 
I got it fixed :D i need blob as in my pc program i use same image you can check here servicepc.net
well good for you. just make sure, next time you post, that you're not using this forum and another one at the same time to get a problem solved without notifying people. that irritates them because it wastes their time in their effort to help you out. the people here mostly check utterAccess.com for cross posters, but I don't think they monitor mysql sites like Oracle. sound good? take care.
 
well good for you. just make sure, next time you post, that you're not using this forum and another one at the same time to get a problem solved without notifying people. that irritates them because it wastes their time in their effort to help you out. the people here mostly check utterAccess.com for cross posters, but I don't think they monitor mysql sites like Oracle. sound good? take care.

Oh no actually fixed by same friend he just sent me the fix as he has no internet and also late for him. Any way i will post the full code here maybe someone may need it too. Just need to get to my laptop.
 
well good for you. just make sure, next time you post, that you're not using this forum and another one at the same time to get a problem solved without notifying people. that irritates them because it wastes their time in their effort to help you out. the people here mostly check utterAccess.com for cross posters, but I don't think they monitor mysql sites like Oracle. sound good? take care.

I *think* the o/p mans their working code is at servicepc.net, not that they cross posted there.?
 
I *think* the o/p mans their working code is at servicepc.net, not that they cross posted there.?
OK. google says it's a remote service for fixing PC issues. if he's getting help there, then my point is pretty valid, cuz he can obviously get more focused attention at that place than he can here.
 
OK. google says it's a remote service for fixing PC issues. if he's getting help there, then my point is pretty valid, cuz he can obviously get more focused attention at that place than he can here.

nop that is my website just working on new one while still under construction i use it for testing my pages/code etc...
 
As i promise maybe some one need it too this will display data from mysql from a table hyperlink text and image (table_name (row text, link,image as (blob) )

Index.php
Code:
<!DOCTYPE html>
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>TV Online</title>
    <link rel="stylesheet" href="./css/bootstrap.css">
</head>
<style>
.cont-wrapper li img {
max-width: 100px;
height: 100px;
width: 100%;
object-fit: cover;
margin: 5px;
border: 2px solid #d55656;
border-radius: 5px;
}
.cont-wrapper li a {
    margin: 10px;
    color: #000;
    width: 100%;
transition: all .3s ease-in-out;
-webkit-transition: all .3s ease-in-out;
padding: 16px 0;
}
.cont-wrapper li a:hover {
color: #d55656;
text-decoration: none;
}
.col-list {
background-color: #1e53abcc;
border-radius: 5px;
}
.cont-wrapper li {
list-style: none;
border: 1px solid #ccc;
border-left: none;
border-right: none;
}
.cont-wrapper li:hover img {
    opacity: 0.8;
}
.cont-wrapper li:first-child  {
  border-top: none;
}
.cont-wrapper li:last-child  {
  border-bottom: none;
}

.cont-wrapper {
padding: 0;
}

@media screen and (max-width: 440px ) {
.cont-wrapper li img {
    max-width: 70px;
    height: 70px;
}
}


</style>
<body>
    <div class="myapp p-5">
        <div class="container">
              <div class="row">
                <div class="col-list col-md-12 col-sm-6 mb-3">
                  <ul class="cont-wrapper mt-3">

                  <?php		
                      require 'conn.php';
                      $query = mysqli_query($conn, "SELECT channel_title,channel_poster,channel_url,cat_id FROM tv_channels order by cat_id");
                      while($fetch = mysqli_fetch_array( $query)){
                  ?>

                    <li  class="d-flex align-items-center">
                        <?php  echo '<img src="data:image/jpeg;base64,'.base64_encode( $fetch['channel_poster'] ).'" >';?>
                        <a href="<?php echo $fetch['channel_url']?>" target="_blank"><?php echo $fetch['channel_title']?>  </a>
                    </li>
                    <?php
					    }
                    ?>
                    
                  </ul>
                </div>
              </div> 
        </div>
    </div>
</body>
</html>

conn.php
Code:
<?php 
    $conn=mysqli_connect("localhost", "db_user", "db_password", "db_name");

        if(!$conn){
            die("Error: Failed To Connect Database!");
        }
?>

download bootstrap v4.1.3 or use only /css/bootstrap.css from it

will look like in picture
attachment.php
 

Attachments

  • Screenshot_2.png
    Screenshot_2.png
    26 KB · Views: 885
ionutp,

I seriously doubt anyone here will understand that massive piece of information you just posted, but you never know! :p When you post a solution in the future, try to tone it down a little bit and communicate it in "small business person" terms. sound good? I may be wrong, but I don't think any Access programmer here would know about, or even care about, a bootstrap concept. but nonetheless, congratulations on your discovery of a solution!
 
Congrats on getting it figured out and thanks for the update!
 

Users who are viewing this thread

Back
Top Bottom