0

In this little snippet of code ,i show how i take the "foto1" column of my database and transfer the value of it to a variable in c# named $foto. The $foto contains the path of the image corresponding to the product that is showing up. Ive tried to copy and paste the path and ditch out the php part and it works. But when i put it in img src it gives me like the broken image thing.And i cant figure out why it does that. All help is aprecciated . Have a nice day :)

   <div class="row shop_box-top">
        <?php
        $ligaBD=odbc_connect('basededadospap','','');
        $sql="SELECT * FROM produto WHERE nome_produto LIKE '%ADIDAS%'";
        $resultado=odbc_exec($ligaBD,$sql);
        ?>
        <div class="row shop_box-top">

        <?php
        while (odbc_fetch_row($resultado))

    {
        $nome = odbc_result($resultado,2);
        $preco= odbc_result($resultado,4);
        $foto = odbc_result($resultado,9);


        ?>



            <div class="col-md-3 shop_box"><a href="stansmithflatwhite.html">
                <img src="<?php echo $foto; ?>" class="img-responsive" alt=""/>
                <span class="new-box">
                    <span class="new-label">Novo</span>
                </span>
                <div class="shop_desc">
                    <h3><a href="stansmithflatwhite.html"><?php echo $nome; ?></a></h3>

                    <span class="actual"><?php echo $preco; ?></span><br>

                </div>

            </a></div>

        <?php }?>
Ricardo Pires
  • 39
  • 1
  • 7
  • what are you getting in $foto. use var_dump() to check it. – Viswanath Polaki Jun 02 '16 at 10:39
  • Is $foto contains logical path or physical path? – Krunal Jun 02 '16 at 10:43
  • @ViswanathPolaki "images/Cal�ado/Adidas/Homem/Stan Smith/ADIDAS STAN SMITH - RED/ch-adidas-stan-smith-red-5.jpg" and images/Cal�ado/Adidas/Homem/Superstar/NEIGHBORHOOD X ADIDAS CONSORTIUM SUPERSTAR 80 10TH ANNIVERSARY -- BLACKGREY/ch-adidas-nbhd-superstar80-blackgrey-5.jpg – Ricardo Pires Jun 02 '16 at 10:53
  • @RicardoPires If you are using physical path like "c:\xyz\abc.jpg" than it would not work in img tag. It must be logical path like "http://localhost/xyz/images/abc.jpg" – Krunal Jun 02 '16 at 10:58
  • @Krunal ohh i understand now , but a physichal path works in just plain html so why doesnt it work when i put it in a variable in php and then call it? – Ricardo Pires Jun 02 '16 at 11:00
  • You must have used file:// protocol in plain html and you must have accessed html file directly using file:// protocol only. "file://" protocol access file on local system. If you use physical path in your script than it will not work when you host your site. So image path need to be logical path instead of physical path – Krunal Jun 02 '16 at 11:08

3 Answers3

0

depends of what path contains the $foto var. If is the absolute path, you have to retrive the relative path. Try also to append an / or an http[s] in front of the path

<img src="/<?php echo $foto;?>">

So it would be : //path/to/photo

Riccardo Bonafede
  • 610
  • 1
  • 9
  • 17
0

As I can see it in your comment, your image paths contain spaces, so a possible solution can be to use urlencode() before echoing them.

xjmdoo
  • 1,658
  • 9
  • 15
0

Try passing full path to img tag like http://localhost/xyz/images/Cal�ado/Adidas/Homem/Stan Smith/ADIDAS STAN SMITH - RED/ch-adidas-stan-smith-red-5.jpg.

Replace "localhost/xyz" with your website directory path.

Krunal
  • 317
  • 1
  • 7
  • I think i might be doing this wrong , here goes the code : " class="img-responsive" alt=""/> – Ricardo Pires Jun 02 '16 at 11:09
  • You need to use add http:// and quotes need to be close proper. Try this – Krunal Jun 02 '16 at 11:16
  • It's better to use php variables $_SERVER['SERVER_NAME'] and $_SERVER['REQUEST_URI'] to build base path instead of hard code the value. You can build path like given here http://stackoverflow.com/questions/2820723/how-to-get-base-url-with-php – Krunal Jun 02 '16 at 11:19
  • im trying the first one still – Ricardo Pires Jun 02 '16 at 11:42