Results 1 to 32 of 32

Thread: Probably really easy - display images

  1. #1

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

    Probably really easy - display images

    I plan to use a frames page to post my photography online.

    In the left frame will be thumnails. Clicking a thumbnail will display the image in the main frame.

    All my photos have a unique ID already - that's how I name them. So my database table looks like this.

    ImageID
    Filename
    Year
    Subject

    Sample data

    ImageID = 18482
    Filename =18482.jpg
    Year = 1995
    Subject = Scenic

    In the PHP page I plan to have two variables that get pre-pended to the filename

    $ThumbPath ='\images\thumbs\'
    $ImagePath = '\images\'

    What is the code for

    1) Populating the images in the left frame based on subject. I know how to write the SQL statement, but how do I make it actually display the thumbs?

    The thumb not only needs to be displayed, but it also needs to be a hyperlink.

    2) When the viewer clicks the thumb, what is the code for displaying the image?

  2. #2
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    This should give you some ideas:

    PHP Code:
     //Connect to the Database before adding these lines
     
    $query mysql_query("select distinct Subject from tableName");
     for (
    $i 0$i mysql_numrows($query); $i++) {
        
    $images mysql_query("select * from tableName where Subject='".mysql_result($query,$i,"Subject")."'");
        
    $ImageId mysql_result($images,$i,"ImageId");
        
    $Filename mysql_result($images,$i,"Filename");
        echo 
    "<a href=\"realImage.php?id=$ImageId\" target="rightFrame"><img src=\"$ThumbPath$Filename\"></a><br>";
      } 
    Then in your realImage.php page use $_GET['id'] to see what image they want to view and pull the Filename out of the database for viewing.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  3. #3

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    Thanks. As I was sitting here thinking about it, I realized that probably all I need to do is put an image on a page and give it a hyperlink and then look at the html.

    I'm busy making up a set of thumbnails now and putting some data in the table so I can play around with this. If I have any more problems, I'll let you know.

    Thanks.

  4. #4

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    cpradio, that's not quite what I'm looking for. I managed to convert your code, but I'm stuck again.

    Basically, I want to have all the subjects (distinct row) in the left frame page.

    Then when the user clicks the left frame page, I want the thumbnails to be displayed in the left frame instead of the subjects along with a link to "Subjects" that will display the subjects again.

    I guess this means when the left page loads I have to check the variable $Subject to see if it contains anything. If it does, then display the thumbnails for that subject, otherwise display the subjects.

    When the user clicks the thumbnail, I want to display the full-size image in the right frame (main.php).

    can you help me with this?

  5. #5

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    Just to make sure I could get it working, I did this: This isn't what I want though because it displays the subject and then all the thumbnails. I plan to upload a couple hundred photographs, so that would be really slow page.

    PHP Code:
    <?php

        $db 
    = @mysql_connect(etc., etc.)

           
    mysql_select_db('Photography');

        
    $query mysql_query("select distinct Subject from Photographs");

        for (
    $i 0$i mysql_numrows($query); $i++) {

            echo 
    mysql_result($query,$i,"Subject");

            
    $images mysql_query("select * from Photographs where Subject='".mysql_result($query,$i,"Subject")."'");

            for (
    $j 0$j mysql_numrows($images); $j++) {

                
    $ImageId mysql_result($images,$j,"ImageId");

                
    $Filename mysql_result($images,$j,"Filename");

                
    $ThumbPath ='images/thumbs/';

                echo 
    "<p align=\"center\"> <img border=\"1\" <img src=\"$ThumbPath$Filename\"></a><br><br>";
               }

           }

    ?>

  6. #6
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    PHP Code:
    //Connect to the Database before adding these lines
     
    $query mysql_query("select distinct Subject from tableName");
     for (
    $i 0$i mysql_numrows($query); $i++) {
       if (isset(
    $_GET['subject'])) {
        
    $images mysql_query("select * from tableName where Subject='".$_GET['subject']."'");
        
    $ImageId mysql_result($images,$i,"ImageId");
        
    $Filename mysql_result($images,$i,"Filename");
        if (
    $i == 0)
          echo 
    "<a href=\"?\">Back To List</a><br>";
        echo 
    "<a href=\"realImage.php?id=$ImageId\" target="rightFrame"><img src=\"$ThumbPath$Filename\"></a><br>";
       } else {
          
    $allSubjects mysql_result($query,$i,"Subject");
          echo 
    "<a href=\"?subject=$allSubjects\">$allSubjects</a><br>";
       }
      } 
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  7. #7

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    cpradio, I'm not clear on what you're doing. It looks to me like the code you wrote will give either one thumbnail per subject or the subject text.

    What I'm looking for is something that gives all the subjects or all the thumbnails from the selected subject.

    Your code only loops through the number of subjects but never addresses the number of thumbnails in the subject.

    I think I'm close, but I don't know how to write this line:

    PHP Code:

    // this is the line I'm having trouble with

    echo "<p><a href=\"$Temp\">\"$Temp\"</a></p>" 
    Here it is in context:

    PHP Code:
        If ($Subject == "")
            {
                echo 
    "Subjects<br><br>";
                
    $query mysql_query("SELECT DISTINCT Subject FROM Photographs");
                for (
    $i 0$i mysql_numrows($query); $i++) {
                    
    $temp mysql_result($query,$i,"Subject")
                    echo 
    "<p><a href=\"$Temp\">\"$Temp\"</a></p>"
                
    }
            }

        else
            {
                
    $images mysql_query("SELECT * FROM Photographs WHERE Subject= $Subject");

                for (
    $i 0$i mysql_numrows($images); $i++) {
                    
    $ImageId mysql_result($images,$i,"ImageId");
                    
    $Filename mysql_result($images,$i,"Filename");
                    
    $ThumbPath ='images/thumbs/';
                    echo 
    "<a href=\"main.php?id=$ImageId\" target=\"rightFrame\"><img src=\"$ThumbPath$Filename\"></a><br>";
                    
    // echo "<p align=\"center\"> <img border=\"1\" <img src=\"$ThumbPath$Filename\"></a><br><br>";
                   
    }
               } 

  8. #8
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Oops, sorry about that. I have been writing this on and off at work and lately its gotten to the point to where I have not had time to thoroughly look at what I wrote.

    The problem with yours is first you do not need \" around the second $Temp as I only use that so the <a href=" "> quotes appear.

    Secondly PHP is case sensative, you have defined the subject name in $temp and not $Temp.

    PHP Code:
    //Connect to the Database before adding these lines
    if (isset($_GET['subject'])) {
     
    $query mysql_query("select distinct Subject from tableName");
     for (
    $i 0$i mysql_numrows($query); $i++) {
        
    $images mysql_query("select * from tableName where Subject='".$_GET['subject']."'");
        
    $ImageId mysql_result($images,$i,"ImageId");
        
    $Filename mysql_result($images,$i,"Filename");
        if (
    $i == 0)
          echo 
    "<a href=\"?\">Back To List</a><br>";
        echo 
    "<a href=\"realImage.php?id=$ImageId\" target="rightFrame"><img src=\"$ThumbPath$Filename\"></a><br>";
     }
    } else {
     for (
    $i 0$i mysql_numrows($query); $i++) {
          
    $allSubjects mysql_result($query,$i,"Subject");
          echo 
    "<a href=\"?subject=$allSubjects\">$allSubjects</a><br>";
     }

    Last edited by cpradio; Jun 17th, 2002 at 02:34 PM.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  9. #9

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    Actually, I figured it out a while ago, but I couldn't post it because VB Forums was down or something. But I actually got it working.

    The frames page is index.htm
    the left frame is index.php
    the right frame is main.php

    PHP Code:
    // index.php

        
    $imgURL ="index.php?NewSubject="// Set subject to Null
        
    echo "<A HREF=$imgURL Target =\"contents\">Subjects</a></br></br>";

        If (
    $NewSubject == ''// User selected to view Subjects
            
    {
                
    $query mysql_query("SELECT DISTINCT Subject FROM Photographs ORDER BY Subject");
                for (
    $i 0$i mysql_numrows($query); $i++) {
                    
    $NewSubject mysql_result($query,$i,"Subject");
                    
    $imgURL ="index.php?NewSubject=$NewSubject";
                    echo 
    "<A HREF=$imgURL Target=\"contents\">$NewSubject</a></br>";
                }
            }

        else    
    // Display thumbnails associated with selected subject
            
    {
                
    $query mysql_query("SELECT ImageID, Filename FROM Photographs WHERE Subject = '$NewSubject'");
                
    //echo "$NewSubject</br></br>";

                
    for ($i 0$i mysql_numrows($query); $i++) {
                    
    $Filename mysql_result($query,$i,"Filename");
                    
    $ThumbPath ='images/thumbs/';
                    
    $ImageID mysql_result($query,$i,"ImageID");
                    echo 
    "<p align=\"center\"><a href=\"main.php?ImageID=$ImageID Target=\"main\"> <img src=\"$ThumbPath$Filename\"></a></p>";
                   }
               } 
    PHP Code:
    // main.php

    if ($ImageID 0)
        {
            
    $db = @mysql_connect(blahblah);
               
    mysql_select_db('Photography');

            
    $query mysql_query("SELECT Subject, Filename, Year FROM Photographs WHERE ImageID = '$ImageID'");
            
    $BasePath 'images/';
            
    $Filename mysql_result($query,0,"Filename");
            
    $FullPath "$BasePath$Filename";
            echo 
    "<p align=\"center\"><img src=$FullPath></p>";
            echo 
    "$Caption</br>";
            
    $Copyright "Copyright ";
            
    $Year =mysql_result($query,0,"Year");
            
    $Author "Paul K. Johnson";
            echo 
    "$Copyright$Year$Author";
        } 

  10. #10

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

  11. #11
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    COOL, looks really good.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  12. #12

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    Originally posted by cpradio
    COOL, looks really good.
    Thanks. And thanks for your help. Now I need a new project. But not a forum.

  13. #13
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Well, first, I would say you should make your script 4.2 compatabile by using

    $imageId = $_GET['ImageId']; right above your if statement in your main.php file

    and $newSubject = $_GET['NewSubject']; right above your if statement in your list.php

    If you are looking for a new project I would attempt a Guestbook with ip logging, and allowing an admin to go in and delete any entries he/she desires.

    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  14. #14

  15. #15
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Okay, content management system.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  16. #16

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    Originally posted by cpradio
    Okay, content management system.
    ????

  17. #17
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    A script were anyone could easily update pages of their site via an online form.

    Add, Remove, Modify text, news, whatever from a Control Panel.

    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  18. #18
    Junior Member
    Join Date
    May 2001
    Location
    Damascus - Syria
    Posts
    16
    guys! guys!
    i really think you really really really should take a look at Lotus Notes....
    have you ever heard of that? ever bothered to check it? i work with Lotus Notes (notes.net), and i came to check this board, and felt really sorry for the way the PHP guys work out there.. here's my advice that may chnage your life forever.. just try it.. it'll be hard at first, just like anything new. it's a powerful database environmet. you put your code and run it in the database, and the server (Lotus Domino) works for you by converting your documents into html pages for online viewing, then u can edit, delete, create and do all that you ever dream to do with PHP, but the difference is that it doesnt need coding, you just make the form, then fill out the documents or edit them online or whatever..
    just take a look, u wont regret it.. check lotus.com and notes.net..
    unfortunately, Lotus and IBM do not make enough advertisement for this, but i think u can do your way through their site. search for "Notes"

    Best wishes!

  19. #19
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by ai.unit
    ...
    You know what the funny thing is? We're programmers, developers, coders...we want to code.

    Ever thought of that?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  20. #20
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by The Hobo
    You know what the funny thing is? We're programmers, developers, coders...we want to code.

    Ever thought of that?
    ROFL

    True, true. If we were that lazy, we might as well download PHP Nuke, and stay restricted to that 'method.' Perhaps you should try coding yourself...

  21. #21
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    BTW...

    That wasn't directed at you, Hobo.

  22. #22
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    even though i have no experience with lotus notes, i can confidently say that there are things you could do in php that prolly couldn't be done in lotus.

    it's like saying "don't make programs in vb because someone else already has" (well maybe )

    :/

  23. #23
    Junior Member
    Join Date
    May 2001
    Location
    Damascus - Syria
    Posts
    16
    thank yo guys for the replies but hey, did i say u dont need to code in Notes? of course we are all developers and coders, but i meant to say that Notes is of a higher level and u never need to bother with the little things again like how to compose the presice HTML of a document etc, because this is a basic functionality in Notes while you can concentrate on your other work, making additional enhancements, and i'm meaning by this the project of Content Management that cpradio suggested earlier which can be done with almost no coding at all, but additional coding would be required (for example) for field validation... (as for me, i do have A LOT of coding in any app i make in Notes, and i work in a company, and we do make projects that take a whole year of development in Notes).
    another thing that got my attention is the way you need to do an sql query to look up data and make a loop... for ready-made queries (i dont know what you call them exactly) there what is called a "view" in notes, and the good thing u'll love about is that it has the ability to process the code you write for each document without the need to get into a loop or something.. of course i'm not making an advertisement here, but i just remember the days i used to work in VB and do all the coding there.. now i'm on a higher level, and i feel the same for PHP..
    of course VB and PHP can do things Notes cant do, no 2 programming langs are the same, but hey, why am i saying all this here?
    well, the actual reason why i came here was because i'm making a photoalbum with Notes, and so far i thought of generating the thumbnails dynamically (the guys at php.net said it wont be that much a heavy load to the server, so it's ok to do it), and i'm willing to have like 10 thumbs per page so it'll be ok.. after looking around, i got the following PHP code wich generates the thumbnail image:
    PHP Code:
    function loadjpeg($path$max_x$max_y) {
     
    $im = @imagecreatefromjpeg($path);
     if (!
    $im) {
       
    $im  imagecreate(15030);
       
    $bgc imagecolorallocate($im255255255);
       
    $tc  imagecolorallocate($im000);
      
    imagefilledrectangle($im0015030$bgc);
       
    imagestring($im155"Error loading $path"$tc);
     }

     if (
    $max_x != && $max_y != 0) {
       
    $x imagesx($im);
       
    $y imagesy($im);

       if (
    $x $max_x) {
         
    $y = (int)floor($y * ($max_x $x));
         
    $x $max_x;
       }

       if (
    $y $max_y) {
         
    $x = (int)floor($x * ($max_y $y));
         
    $y $max_y;
       }

       if (
    imagesx($im) != $x || imagesy($im) != $y) {
         
    $tmp imagecreate($x$y);
         
    imagecopyresized($tmp$im0000$x$yimagesx($im), imagesy($im));
        
    imagedestroy($im);
         
    $im $tmp;
       }
     }

     return 
    $im;

    as i could understand the code takes the url of the image along with a maximum dimension parameter and returns the tiny image, but my problem is that i'm still a total nerd in php, and luckily enough, my web host offer PHP functionality in the hosting package alongside with Lotus Domino, anyway,i just thought of showing you what i'm willing to do so u may help me with this as it's being hard for me to deal with PHP...

    my problem in the previous function was how to pass the parameters, but reading through this thread i found out that i can do something like www.thing.com/page.php?imgurl=so&so&size=xyz

    so here's what i'm willing to do to get a single thumbnail:

    in html:
    <img src="phpPath/getthumb.php?url=imgurl">

    and in the php file (getthumb.php) i'd have the function mentioned above and the following:

    PHP Code:
    if (isset($_GET['url'])) {
        
    $max_x 150
        $max_y 
    150
        
    return loadjpeg($_GET['url'], $max_x$max_y)
    }


    [
    I]function loadjpeg goes here[/I
    so tell me, it'll work like this, no? i will give it a try this evening..
    -/-

  24. #24
    Junior Member
    Join Date
    May 2001
    Location
    Damascus - Syria
    Posts
    16

    Unhappy

    well it didnt work...
    you can try it here:
    http://yusran.com/php/php.exe/getthu...sf/head-en.gif!OpenImageResource

    any ideas?

    here's my complete php code

    PHP Code:
    <?php
    if (isset($_GET['url'])) {
        
    $max_x 150;
        
    $max_y 150;
        return 
    loadjpeg($_GET['url'], $max_x$max_y);
    }


    function 
    loadjpeg($path$max_x$max_y) {
     
    $im = @imagecreatefromjpeg($path);
     if (!
    $im) {
       
    $im  imagecreate(15030);
       
    $bgc imagecolorallocate($im255255255);
       
    $tc  imagecolorallocate($im000);
      
    imagefilledrectangle($im0015030$bgc);
       
    imagestring($im155"Error loading $path"$tc);
     }

     if (
    $max_x != && $max_y != 0) {
       
    $x imagesx($im);
       
    $y imagesy($im);

       if (
    $x $max_x) {
         
    $y = (int)floor($y * ($max_x $x));
         
    $x $max_x;
       }

       if (
    $y $max_y) {
         
    $x = (int)floor($x * ($max_y $y));
         
    $y $max_y;
       }

       if (
    imagesx($im) != $x || imagesy($im) != $y) {
         
    $tmp imagecreate($x$y);
         
    imagecopyresized($tmp$im0000$x$yimagesx($im), imagesy($im));
        
    imagedestroy($im);
         
    $im $tmp;
       }
     }

     return 
    $im;
    }
    ?>
    -/-

  25. #25
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by ai.unit
    well it didnt work...
    Ohh... the irony of it all

  26. #26
    Junior Member
    Join Date
    May 2001
    Location
    Damascus - Syria
    Posts
    16

    Question

    Originally posted by mendhak
    Ohh... the irony of it all
    So? ...
    -/-

  27. #27
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    It's best you start a new thread, explaining your problem. That should elicit more responses.

    By the way, where in Damascus do you live? I used to live there myself

  28. #28
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by ai.unit
    guys! guys!
    i really think you really really really should take a look at Lotus Notes....
    have you ever heard of that? ever bothered to check it? i work with Lotus Notes (notes.net), and i came to check this board, and felt really sorry for the way the PHP guys work out there.. here's my advice that may chnage your life forever.. just try it.. it'll be hard at first, just like anything new. it's a powerful database environmet. you put your code and run it in the database, and the server (Lotus Domino) works for you by converting your documents into html pages for online viewing, then u can edit, delete, create and do all that you ever dream to do with PHP, but the difference is that it doesnt need coding, you just make the form, then fill out the documents or edit them online or whatever..
    just take a look, u wont regret it.. check lotus.com and notes.net..
    unfortunately, Lotus and IBM do not make enough advertisement for this, but i think u can do your way through their site. search for "Notes"

    Best wishes!
    lotus notes??? not even in the same ball park. for one it is expensive (what else did you expect from IBM) and only runs in windows (and mac) environment. at least that is what I read. php can run anywhere. php is FREE, lotus notes is not.

    you can't come here to tell us that you feel sorry for us becasue notes is soooo much better than php. well if you like it so much then don't do php. also you can only work with what the environment will let you work with, if you have to run notes than fine, run it, but we can't or don't want to so we don't.

  29. #29
    Junior Member
    Join Date
    May 2001
    Location
    Damascus - Syria
    Posts
    16
    Originally posted by mendhak
    It's best you start a new thread, explaining your problem. That should elicit more responses.

    By the way, where in Damascus do you live? I used to live there myself
    yea right.. i think i will make a new thread on php.net...

    you were in Damascus in Syria? i heard there's a city called damascus in the US so u maybe mistaking anyway, i'm in the mazra3a area. that's almost near to shahbandar square next to the central ministry where were u staying in damascus?
    -/-

  30. #30
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    and where on php.net will you be making this thread????

  31. #31
    Junior Member
    Join Date
    May 2001
    Location
    Damascus - Syria
    Posts
    16
    Originally posted by phpman
    and where on php.net will you be making this thread????

    good Q! i thought there's a public forum.. but i reemmbered that one can post a msg in the functions secion of the site.. i think i'll post it under the 'imagecreate' function...

    or maybe here on this forum... or even both.. LOL.. i was in a hurry to find the answer why my code wasn't working, but now i am assigned some work, and i aint free as much as i was a few days ago...
    -/-

  32. #32
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by ai.unit
    yea right.. i think i will make a new thread on php.net...

    you were in Damascus in Syria? i heard there's a city called damascus in the US so u maybe mistaking anyway, i'm in the mazra3a area. that's almost near to shahbandar square next to the central ministry where were u staying in damascus?
    Rabat Building, just near Damascus Community School. Great place, I really liked it. I especially like Sookh Hamidiye for some reason.

Posting Permissions

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



Click Here to Expand Forum to Full Width