SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Member Lukus's Avatar
    Join Date
    Oct 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP + Pictures . . .

    Hi, im testing something out and i wanted to get a picture from a DB. This is the code i used:

    PHP Code:
    echo("<p><img src=" $row["picture"] . "</img></p>");
        } 
    Everything works and it tried to find a picture, except the picture it tries to find is http://images-eu.amazon.com/images/P/B00005LDIU.02.MZZZZZZZ.jpg</img

    I need to know what to put in the code to make it display the picture.

    Cheers
    ________
    Luke

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, not sure what's in your db, but I just hardcode the URL into the db and call the URL from there. Is that what you're doing?

    Sketch
    Aaron Brazell
    Technosailor



  3. #3
    SitePoint Member Lukus's Avatar
    Join Date
    Oct 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nah in my DB ive got a field called "picture", which just contains a url, so i want it to do <img src="the url in the DB"</img>
    I did it this way cos i think it wud be easier just typing a URL instead of having to put <img src... everytime i enter new data.

  4. #4
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay then you need to have an ID attached to the link so when the link is clicked on, that ID is passed along and you do a (SELECT * FROM dbname WHERE id='pictureid')...that's a rough version of it anyway. You get what I'm saying right? I'd need to look at my reference at home to make sure I got the syntax right, but that's the gist of it.

    Sketch
    Aaron Brazell
    Technosailor



  5. #5
    SitePoint Member Lukus's Avatar
    Join Date
    Oct 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    um i dont wanna have a link i just wanna show the picture , i was wondring what id have to put in the original code to make the <img src... work for the data in the DB and show the picture

  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in yoiur db you have the image url and a primary key such as graphic_ID, correct? if not, you need to have something along these lines. Secondly, in order to have the correct image displayed, you need to pass on a separate id to the <img src> so that the PHP can say, "Okay, which record in the db has the same graphic_ID as the img src ID I am looking for? Oh here it is, I'll display this..."

    Does that make sense?

    Sketch
    Aaron Brazell
    Technosailor



  7. #7
    SitePoint Member Lukus's Avatar
    Join Date
    Oct 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeh thanks - got it now

    also do u know how i can make each picture be displayed on a new row of my table??

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is </img> some sort of new XHTML standard, I have never used such a thing.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes Freddy. XHTML requires that you close ALL tags. He could shorthand it by doing something like this:
    Code:
    <img src=url />
    This notation requires a space at the end before the slash.

    Sketch
    Aaron Brazell
    Technosailor



  10. #10
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Lukus
    yeh thanks - got it now

    also do u know how i can make each picture be displayed on a new row of my table??
    If you want to display all the pictures in your db, you could set the number of <TR>'s equal to the number of picture ID's.

    sketch
    Aaron Brazell
    Technosailor



  11. #11
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to get each picture on a new row he surely just needs to put the array in a while loop and for element just open and close <tr> tags?!
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  12. #12
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that makes sense...

    Sketch
    Aaron Brazell
    Technosailor



  13. #13
    SitePoint Member Lukus's Avatar
    Join Date
    Oct 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Soz

    Cheers for ya help everyone, i h8 to be annoyin but:

    If you want to display all the pictures in your db, you could set the number of <TR>'s equal to the number of picture ID's.

    sketch
    um how?

    chrz again
    ____
    Luke

  14. #14
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to point out that the code you used to call the image is incorrect.

    You said:
    echo("<p><img src=" . $row["picture"] . "</img></p>");
    }

    You're leaving out the closing > for the opening IMG tag. It might be a typo but I wanted to point it out just in case you missed it.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  15. #15
    SitePoint Member Lukus's Avatar
    Join Date
    Oct 2001
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cheers

    cheers i didnt see that - can ne1 help me with the table rows?
    Luke

  16. #16
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    assuming you are calling your images in a loop via the mysql_fetch_array command just add this:

    echo("<tr><td><Img src=".row["picture"]."></td></tr>");

    You might need to escape all those " (or use ')
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  17. #17
    SitePoint Zealot Hulkur's Avatar
    Join Date
    Oct 2001
    Location
    Estonia
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    echo("<p><img src="*.*$row["picture"]*.*"</img></p>");
    should be:
    echo("<p><img src=\""*.*$row["picture"]*.*"\"/></p>");
    (2B) or (not 2B) = FF

  18. #18
    SitePoint Addict AbelaJohnB's Avatar
    Join Date
    Oct 2001
    Location
    Eureka, CA. USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:


    Code:
    <TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" ALIGN="" WIDTH="">
    <?php 
        for ($i=0;$i<count($Total_Results);$i++) {
    ?>
    
      <TR>
        <TD><IMG SRC="<?=$row["picture"];?>" BORDER="0" ALT=""></TD>
      </TR>
    
    <?
        }
    ?>
    </TABLE>


    Later.
    John B. Abela
    www.JohnAbela.Com

  19. #19
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    should be:
    echo("<p><img src=\"" . $row["picture"] . "\"/></p>");
    Quotes are optional unless this needs to be xhtml compliant.

    Also if you want to get technical I would have done it like this.
    PHP Code:
    ?>
    <p><img src="<?=$row["picture"]?>" width="xx" height="xx" alt="Alt Text" border="0"></p>
    <?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  20. #20
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    John, you beat me to it, great minds think alike, eh?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  21. #21
    SitePoint Addict AbelaJohnB's Avatar
    Join Date
    Oct 2001
    Location
    Eureka, CA. USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by freddydoesphp
    John, you beat me to it, great minds think alike, eh?





    Now let's just hope he understands:

    PHP Code:
    count($Total_Results); 


    John B. Abela
    www.JohnAbela.Com


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
  •