Link to home
Start Free TrialLog in
Avatar of e4art
e4artFlag for United States of America

asked on

Calling Up Thumbnail with Category Name

Would anyone know how to call up the most recently added photo added to a subcategory in a gallery-- to be placed with the subcategory name?  Someone mentioned that you could simply call up the photo with the highest ID at the time.  I'm new to PHP and I'm not sure how to go about doing this.  Need Help Please!  Here's some of my gallery code:  Is this the page it should go on?

<?php

        // initialization
        $result_array = array();
        $counter = 0;

        $cid = (int)($_GET['cid']);
        $pid = (int)($_GET['pid']);

        // Category Listing

 if(!$cid)
 {
echo "Select a category";
} else if ($cid && !$_GET['thumb']) {
            
 $result = mysql_query( "SELECT * FROM gallery_category WHERE parent_id = $cid" );
$num = 1;
echo "<table width='100%' border=1><tr>";
                        
while( $row = mysql_fetch_array( $result ) )
                {
$catname = $row['category_name'];
$catid = $row['category_id'];
                        
 echo "<td><a href='album.php?cid=".$catid."&thumb=1&ocid=$cid'>".$catname."</a></td> ";
 if ($num == '3') {
 echo "</tr><tr>";
 $num = 0;
 }
 $num ++;
                              
  }
echo "</tr></table>";
 }

// Thumbnail Listing

else if( $cid && $_GET['thumb'] )
 {
                $number_of_thumbs_in_row = 4;

                // If current page number, use it
                // if not, set one!

                if(!isset($_GET['page'])){
                    $page = 1;
                } else {
                    $page = $_GET['page'];
                }

                // Define the number of results per page
                $max_results = 12;

                // Figure out the limit for the query based
                // on the current page number.
                $from = (($page * $max_results) - $max_results);

                $result = @mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."' LIMIT $from, $max_results");

                $nr = @mysql_num_rows( $result );

                if( empty( $nr ) )
                {
 $result_final = "\t<tr><td><div align=\"center\"><strong>No images in category found!</strong>
<br><br><font size=\"2\"><a href='album.php?cid=".$_GET['ocid']."'>Back to Photo Gallery Category List</a></font>
 </div></td></tr>\n";
                }
                else
                {
                        while( $row = mysql_fetch_array( $result ) )
                        {
                                    
//this is where we were able to add a caption/etc. under our thumbnail in the gallery.
                        $result_array[] = "<a href='album.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /><br />".$row[0]."</a>";
                        }
                                    
                        mysql_free_result( $result );
                                    
                        $result = @mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" );
                        list($category_name) = mysql_fetch_array( $result );
                        mysql_free_result( $result );
                                    
$result2 = @mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($_GET['ocid'])."'" );
$row = mysql_fetch_object( $result2 );
$ocid = $row->category_name;
$result_final = "<tr><a href='album.php?cid=".$_GET['ocid']."'>$ocid</a> &gt; $category_name<br><br>";
                                    
//Think this might also be where you can add your caption below image?
                                     
                                             
 foreach($result_array as $thumbnail_link)
                        {
                                if($counter == $number_of_thumbs_in_row)
                                {        
                                        $counter = 1;
                                        $result_final .= $category_link."\n</tr>\n<tr>\n";
                                }
                                else
                                $counter++;

                                $result_final .= "\t<td><div align=\"center\">".$thumbnail_link."</div></td>\n";
                        }
       
                        if($counter)
                        {
                                if($number_of_photos_in_row)
                        $result_final .= "\t<td colspan='".($number_of_thumbs_in_row)."'></td>\n";
                        $result_final .= "</tr>\n";
                                    
                                    
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM gallery_photos WHERE photo_category=".addslashes($cid).""),0);
$select_list = "<select size=\"1\" onchange=\"document.location=this[this.selectedIndex].value\">";

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

//Below here is where I have my prev/next page links.
Avatar of steelseth12
steelseth12
Flag of Cyprus image

If you could expain what you would like to do wilth the last most recently added photo we could tell you what you need to do .... also the highest autoincrement id will get the last photo only if there has not been any photos updated
Avatar of e4art

ASKER

I have my top categories listed to the left side of my web page.  You click on one of the top categories (eg: Editorial) and it brings up the sub categories in the center of my web page (News, Sports. Entertainment, Features, etc).  That's working fine.  Just the list of subcategory NAMES are coming up right now.  I'd like the most recently added photo (thumbnail) within each subcategory to appear with each subcategory name.  
What do you mean that we can get the highest autoincrement id only if there has not been any photos updated.  What do you mean by "updated."  In what way would a photo be updated.  Thanks.
Lets say you have 4 photos in your table

ID   photo
1   image1
2   image2
3   image3
4   image4

if you update image2 with image5


ID   photo
1   image1
2   image5
3   image3
4   image4

then no longer the highest id has the newest image.
Avatar of e4art

ASKER

Well now you've got me thinking.  Let's say I have thousands of images (eventually) and I have an archive section where images were uploaded months ago regarding a certain subject.  Then all of a sudden I found another image from that group that I forgot about and wanted to upload that image as well.  No that image is going to have the highest id, even though that is an from an older story or subject.  Now what do I do?  How do I work with this issue?  Any ideas?  How should I be calling up these images then.  No longer by the highest id then, correct?  Maybe I somhow alter how an images is updated?  Maybe if I have "image1" "image2" "image3" and I want to add another image to this area, do I just find the images the photo is linked to (by story) and give it a name like "image3a" instead of the autoincrement which could be "image100"?  Sound silly?  Maybe so.  Or should I manually go ahead and select the thumbnail to be shown with each subcategory name?   Just thinking how I can get around this.  I want to figure out a process which in the end will take as little work as possible to maintain the website.  I was hoping this section can automate itself, but now I don't know.  What's your take on this.
I would add a column in the table to lets call it ordering.
When you insert a new image you can select the max record in the orderring column and increment it by 1.
when you select the thumb to show with the category litle just select MAX(ordering).
Now if you change the ordering of the images you can do so by changing their number in the ordering column.
Avatar of e4art

ASKER

A bit confused here.  I understand the first part, but what do you mean by "Now if you change the ordering of the images you can do so by changing their number in the ordering column."  Are you saying that I'd have to go into my MySQL table to change the ordering of the photo number?  Would this only happen when I want to update a photo.  Otherwise, the max(ordering) is just pulling the highest id anyway, yes?  You're just saying that when I update an image, I can go in and change it's ordering so it's not the highest?  Sorry, just a bit confused to how this will work.  Can you show me some sample code?-- Or how this will work with my code above?  Thanks.
Im talking in your backoffice where you upload you images you can have a textarea/listbox etc displaying the image's order and change it accordingly.
Avatar of e4art

ASKER

Yes I have an upload form, but actually all images uoloaded will be going to an administration page first where I will decide if want to approve or deny the image.  I'm guessing that at that point (the admin. page) is where I can reorder the image accordingly.  Does this sound correct?  
I don't have my admin. page set up just yet, as this is a large challenge for me, but I do have plenty of code to work with already if you'd like to help me out with that?  Or would that be a separate question.  You could let me know where in the page to place this code to set the image order.  I have an editphoto.php file, login.php file, security file, etc. obtained from the same tutorial I created my gallery from, but I'm confused about how to work with it.  I go to login and nothing happens.  Would you be able to help me with that first, and then implement this image order feature??  I'd really appreciate it.
Im sure all the experts here will do their best to help you set up you site, but you must realize that this is not our real job, and i dont think anyone would have the time to guide you on their own from begin to end.
It would be best if you broke it up in to small questions so we can all help you .
Avatar of e4art

ASKER

Sure, I understand.  For now, do you tink that would be appropriate if I re-order an updated image at the admin page, when I decide if I'm going to approve an image or not?
ASKER CERTIFIED SOLUTION
Avatar of steelseth12
steelseth12
Flag of Cyprus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of e4art

ASKER

Can you illustrate how this code will work?  See some of my code at the top.  This is part of my code from the photo gallery page.  Can you implement what you're taling about into my code please?  Please also reiterate the changes to be made to my MySQL table.  Thanks so much.