Hello
I have some doubts about getting images that are related to the data of my DB.

Lets say that I click on a link called "Superman" in a list of names, so I go to a page with all the info about Superman that comes from my database, and I want to get his picture from a folder called images.

I have done this:

echo "$id";
echo "$superheroe";
echo "<img src=\"../images/$id.jpg\">";

I have named the image the same as the ID of superhero so my logic (maybe not too logic) is that if the ID = superman the image must be named superman too. I only can´t make the relations between that folder and the php code.

Any orientation will be BigTime appreciated

Thanks in advance

    1. Store your images in a folder on your server. For example, if you have 1.jpg, put it in: /home/my/directory/images

    2. Store the path of this 1.jpg in a column of your db with the associated record. So if you have a user called "superman" and you want his picture stored, possibly create column called "image_paths" in the same table. Now there should be a field with the entire path to the picture (/home/my/directory/images/1.jpeg).

    3. When you do a query for the "superman" record, also get the the "images_path" column and do:

      <?php
      $image = $row['images_paths']
      ?>
      
      <img src = "<?php echo $image; ?>">
      

      Hi, thank you for your help. I will try it out!

      Just one question.
      I just don´t know how to add the path of the images folder in mysql. I mean, Do I create a field called images_path and then I insert the records just like ../htdocs/mysite/image_path/myimage.jpg?

      Thank U

        What I had in mind was creating a column in your table called "images_paths" (or whatever you feel appropriate with calling it).

        If you already have a table setup and simply want to add the images_path column to it, see the ALTER TABLE command:

        http://dev.mysql.com/doc/mysql/en/ALTER_TABLE.html

        As far as inserting the path to your image into the table, you could do it in PHP as follows:

        
        $name = "superman";
        $image_src = "/home/my/directory/images/myImage.jpg";
        
        $sql = "INSERT into myTable
                (username, images_path)
                VALUES
                ('$name', '$image_src')";
        
          Write a Reply...