Solved

Calling Up Thumbnail with Category Name

Posted on 2007-04-01
12
219 Views
Last Modified: 2013-12-12
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.
0
Comment
Question by:e4art
  • 6
  • 6
12 Comments
 
LVL 20

Expert Comment

by:steelseth12
Comment Utility
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
0
 

Author Comment

by:e4art
Comment Utility
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.
0
 
LVL 20

Expert Comment

by:steelseth12
Comment Utility
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.
0
 

Author Comment

by:e4art
Comment Utility
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.
0
 
LVL 20

Expert Comment

by:steelseth12
Comment Utility
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.
0
 

Author Comment

by:e4art
Comment Utility
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.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 20

Expert Comment

by:steelseth12
Comment Utility
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.
0
 

Author Comment

by:e4art
Comment Utility
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.
0
 
LVL 20

Expert Comment

by:steelseth12
Comment Utility
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 .
0
 

Author Comment

by:e4art
Comment Utility
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?
0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
Comment Utility
I would put it in the image section of the categories/subcategories so that its easy to manage the images while editing a subsection and  in the future if the website gets larger enough it will be accessible by many users without them having to have permissions to more sensitive areas.
0
 

Author Comment

by:e4art
Comment Utility
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.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now