0

I have the flowing sql query the MainImage datatype is image (think binary)

SELECT dbo.tbl.strPartNumber AS SKU, dbo.tbl.strDesc AS ProductName, dbo.tbl.strExtendedDesc AS ShortDesc,
        (SELECT TOP 1 dbo.tblImg.imgData FROM dbo.tblImg WHERE dbo.tblImg.strpartnumber = dbo.tbl.strpartnumber AND bitDefaultImage = '1') as MainImage,
        dbo.tbl.bitInactive AS Inactive FROM dbo.tbl WHERE bitWebstoreItem = '1'

now I can get all data to show but not the image this what I have for the img show

what I would like to do is select image from outside datasource and add it to new or existing product in woocommerce

$DefaultImage = base64_encode($row["MainImage"]);
if (isset($DefaultImage) && $DefaultImage !== null) {
    echo '<td align="center" style="border-color:#000000"><img src="data:image/jpeg;base64,' . $DefaultImage . '" width="150" height="150"></td>';
        } else {
        echo "<td align=\"center\" style=\"border-color:#000000\">No image available.</td>";
    }

it only shows a broken image

I have search the forum and no solution is found yet

I have done a var_dump and get string(0)

I read the following https://stackoverflow.com/questions/10958350/display-image-in-php-page-from-sql-database but this is for only the images.

also this https://stackoverflow.com/questions/55785364/update-image-in-php-and-mysql-database

EDIT

SCREENSHOT OF DATA enter image description here

13
  • So have you checked what the base64-encoded string looks like? Is it definitely a valid image? Commented Feb 19, 2024 at 11:28
  • @ADyson yes I can see that in the database it has data in it? what type I do not know. it is jpeg or jpg, webp, png Commented Feb 19, 2024 at 11:33
  • 1
    Right... so data:image/jpeg is a bit of an assumption then? Try testing it with an image you've prepared and you know is definitely a JPEG. Also I know you can see the data in the database - but if you look again, that wasn't what I asked you. Commented Feb 19, 2024 at 11:35
  • @ADyson appologies, the encodes string is empty. Commented Feb 19, 2024 at 11:42
  • 1
    Why should I not upload images of code/data/errors? . Also, the context is unclear. Is that you showing me the data at source in the database? Again, that wasn't what I asked Commented Feb 19, 2024 at 11:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.