Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: photo album info loaded from php/db

  1. #1
    Join Date
    Nov 2005
    Location
    Austin TX,US
    Posts
    71
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default photo album info loaded from php/db

    Hi,

    I want to do a photo album: Index page list all thumbs. Click will lead to the larger image with info [date, with...,...] fed from a db.

    With HTML: I need to have one html page for one large img, so if I have e.g. 100 thumbs, I need to have 100 html pages!!!

    I know with php / mysql I can have only one page for the large img. How do I do it? Could you point me to some tutorial or better yet show me how to do it?

    Right now, I have a db for all img: img_id, img_name, img_place, img_category. But have no clue about doing php.
    Thanks

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Well... there's a script here on DD that does exactly what you're saying.

    However... here's what i'd suggest:

    making the index with the thumbnails, in whatever way you want.
    Have the images linked to:
    http://.../bigimages.php?image=name

    Then, on your next page, do something like:
    PHP Code:
    <?php
    $img 
    $_GET['image'];
    echo 
    '<img src="http:/....yourdirectory/'.$img.'.jpg">';
    ?>
    That example would make "name.jpg" appear on your page.

    It needs work, but that depends on what you want, exactly.

    That's 1 page, rather than 100. Which is nice

    And... using a database would be the same idea.
    Instead of ?image=name, use ?image=id.

    Then on your next php page, get the id ($_GET['image']), and search the database for info about that image, display that, and you're done. Same idea.

  3. #3
    Join Date
    Nov 2005
    Location
    Austin TX,US
    Posts
    71
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33
    And... using a database would be the same idea.
    Instead of ?image=name, use ?image=id.

    Then on your next php page, get the id ($_GET['image']), and search the database for info about that image, display that, and you're done. Same idea.
    Hi,

    I'm still struggling with this, not yet have a file that works, and don't want to use the script that we already have in DD for photo album. I prefer your way.

    Could you give an example of displaying the big img and e.g. img_place info from db? I'm not clear how things are connected. Thanks.

    Ex:

    index.php:
    <a href="listing_detail.php?image=id"><img src="img/paparazzi_small.jpg" class="thumb"></a>

    listing_detail.php file:
    <?php
    $img = $_GET['image'];
    ......
    ?>

    mysql db:
    1. id
    2. bigImg_name
    3. bigImg_place

    How do I connect everything to img id?

    Thanks a lot!

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Look into mysql.
    http://www.php-mysql-tutorial.com/
    Great tutorial, I say.

    basically, you just need to get the info (as shown very clearly there) and display where you want. ...like:
    PHP Code:
    echo $variable
    Your id, bigImg_name, etc etc aren't important. They will just be things in the database you will get with the rest of the data.

    The tutorial should give you lots of (easy) info.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Nov 2005
    Location
    Austin TX,US
    Posts
    71
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I've just found out a way to do:
    In the index that lists thumbnails:I put e.g.:
    <a href="listing_detail.php?id=23"><img src="img/paparazzi_small.jpg"></a>

    and then in the listing_detail.php: I put:

    $id = $_GET['id'];
    $query="SELECT * FROM movie WHERE id='$id' ";
    ......

    Is it the right way, and good way to do?Is it the same as what you showed me?

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Yes. This is exactly what I was talking about. It'll work well
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Is it the right way, and good way to do?
    I haven't followed this thread, but that snippet of code, without relation to anything else, has one major problem. It's vulnerable to SQL injection attacks.
    Say, for example, someone went to listing_detail.php?id=%3D%27%3Bdrop%20database%20dbname%3Bselect%20*%20from%20movie%20where%20id%3D%27

    The query would become:
    Code:
    $query="SELECT * FROM movie WHERE id='';drop database dbname;select * from movie where id=''";
    ... which, unless you'd set up the permissions properly (which most people don't bother with), would spell doom for your database.
    The solution is:
    Code:
    $id = mysql_real_escape_string($_GET['id']);
    That must be called after mysql_connect().
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    For security, Twey is right. Don't think your script is wrong though... just that it isn't (now is, if you use his suggestion) secure.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Nov 2005
    Location
    Austin TX,US
    Posts
    71
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks Djr33 & Twey for your timely & knowledgeable help to all of my questions so far! Truly appreciated!!!

    the SQL injection that Twey was talking about, is it able to delete my whole db?
    Are there any more major security issues that php beginners like me should pay close attention to? Tks
    Last edited by mtran; 05-09-2006 at 08:43 PM.

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    the SQL injection that Twey was talking about, is it able to delete my whole db?
    If the user you are executing the query as has permission to, yes.
    Are there any more major security issues that php beginners like me should pay close attention to? Tks
    Yes. Too many to list here. See http://www.phpsec.org/.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •