How to display an image in php using MySQL?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomannasim786
    New Member
    • Feb 2010
    • 4

    How to display an image in php using MySQL?

    Hello,
    I've a PHP page where I've different links representing different albums.

    What I want is, when user clicks on any album link he will b redirected to "images.php " where all images related with that album are displayed. I am using MySQL and image names are stored in images->image_name.

    Plz tell me geniuses how to accomplish this task?

    (I've set up relation between albums and images tables using album_id column. My database has two tables:
    1- Albums - which consist of following fields (album_id, album_name)
    2- Images - which consist of following fields (image_id, image_title, image_name, album_id) )
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    Is the image_name column the file name?

    Comment

    • nomannasim786
      New Member
      • Feb 2010
      • 4

      #3
      Yes. This is the file name.
      e.g, abc.jpg

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        Then give images.php the album id in the URL's query string and use it to get the images for that album. You make sure the ID is given, make sure the ID is valid, and create an array of all of the images. You can ten build the display based on these facts. I've provided an example for deriving these facts:

        images.php
        Code:
        // Ensure an ID was sent
        if (isset($_GET['id'])) {
          $album = mysql_fetch_object(mysql_query("select * from `albums` where `album_id` = " . (int)$_GET['id']));
        
          // Ensure the ID is valid
          if ($album) {
            $result = mysql_query("select * from `images` where `album_id` = " . $album->id);
            $images = array();
        
            while ($image = mysql_fetch_object($result)) {
              $images[] = $image->name;
            }
          }
        }

        Comment

        • nomannasim786
          New Member
          • Feb 2010
          • 4

          #5
          Thanx Sir.
          But I'm actually a beginner so exert hard in understanding the procedure, plz tell me in more detail. I'ld b very thankful 2 u.

          Comment

          • kovik
            Recognized Expert Top Contributor
            • Jun 2007
            • 1044

            #6
            Sorry, but you'll need to show more effort that that, first. We're here to help you help yourself. I've already given you more than I usually do.

            Comment

            • nomannasim786
              New Member
              • Feb 2010
              • 4

              #7
              Ok I'll. Thanx 4 ur tym. :)

              Comment

              Working...