SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot Charlie_chalk's Avatar
    Join Date
    Sep 2002
    Location
    THE North East, UK
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    linking images to mySQL database

    Hi

    I understand its better to link images to you mySQL database than to put them in there. Can someone please tell me how I do either/both. I have to use phpmyadmin (host won't allow anything else).

    When I put a link into the field it just outputs the link when called from my PHP page.

    I've just created my first mySQL/PHP test thingy tonight, so I'm very new to all this, sorry if I sound thick!

    Thanks

    Steven

  2. #2
    SitePoint Evangelist compwizard's Avatar
    Join Date
    May 2002
    Location
    United States
    Posts
    457
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all, you need to have a table with some fields, and a path field...something like this:
    PHP Code:
    ID PICPATH 
    ------------
    1  image1.jpg
    2  
    test654.jpg
    3  
    image5.jpg
    4  
    cat.jpg
    5  
    lion.jpg 

    Then you need a sql statement like this:

    PHP Code:
    <?php
        mysql_connect
    ("localhost""mysql_user""mysql_password") or die("could not connect");
        
    mysql_select_db("mydb");

        
    $result mysql_query("SELECT id, picpath FROM mytable");

        while (
    $row mysql_fetch_array($result)) {
        echo 
    "ID: " $row[0] . " PIC = <img src='" $row[1] . "'><hr>";       

       }

        
    mysql_free_result($result);
    ?>
    Something similar to that anyway...you just have to use an HTML img tag with the src= to the picpath.
    Compwizard
    "There are 10 kinds of people in this world -- those who know binary, and those who don't."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •