Hello everyone, I encountered such a problem and do not know how to solve it, please tell me.

There is a php code:

<?php $id = $_GET["id"]; $sql = mysql_query("SELECT newyear FROM tb_image WHERE id = '$id'"); $image = mysql_result(0, 0, $sql); echo "<img src = '$image'> ?> 

And I need a user who would put the code on his website about this form:

 <script src = "http://site.ru/newyear.php?id=1"></script> 

and he will have a code installed in that place, a picture will be displayed which will be received from the database?

    3 answers 3

    Easier option

    code for placement <img src='http://site.ru/newyear.php?id=1'>

     <?php $id = $_GET["id"]; $sql = mysql_query("SELECT newyear FROM tb_image WHERE id = '$id'"); list($image) = mysql_fetch_array($sql); header("Content-Type: image/jpeg"); //здесь может быть ваш код :), если у вас не jpeg header("Content-Length: " . filesize($image)); readfile($image); ?> 

    If you need exactly <script src = "http://site.ru/newyear.php?id=1"></script> , then

     <?php $id = $_GET["id"]; $sql = mysql_query("SELECT newyear FROM tb_image WHERE id = '$id'"); list($image) = mysql_fetch_array($sql); echo "document.write('<img src=\'http://site.ru/$image\'>')"; ?> 

    But it is better not to use this option.

    And you are strange using mysql_result.

      Your script should give the picture itself. Look towards the GD library.

        Why is your echo not closed? What kind of idiotic desire to store pictures in the database?

        If it’s not so easy to make a directory like / banners / put index.php .htaccess there that would throw all requests to index.php and index.php that would pull the image from the base and make it echo (if necessary, give the desired title).

        In my opinion, it is transparent enough for the final site. requests will go to virtual images that are physically located in the database.

        Despite the delusional ideas of the author, I tried to solve the problem.

        And do not say that what I wrote is nonsense, what question is the answer.

        • Violently! But not in the case. - KaZatsa
        • I do not agree, the presented option is just good. Well, the code - sort things out without me anyway, don't do it all for you. - Sergey