Build An Automated PHP Gallery System In Minutes

I have the exact same problem the code works fine but a maximum of 6 files is saved and inserted into the database, the is lost somewhere in the process without any errors!
Has someone found a solution or at least a cause for this strange bug?

thx in advance
Peter

ps. plz don’t mind some possible spelling mistakes, english isn’t native to me.

Hi, I’m new to these forums (although I’ve browsed the Sitepoint site many times before :stuck_out_tongue: ) and I found this script yesterday. It works very well and I found it easy to modify to fit my site’s look, and it’s a lot easier than making a “gallery” with static HTML. I just have a question… on the main viewgallery page, where it’s supposed to show each of the categories, how would I go about showing the first thumbnail from that category above the category name? I’m sorta new to Mysql, and any help would be greatly appreciated! :slight_smile:

Hi,

Work through this code … Designed to do what you are after:

	$sql = mysql_query("SELECT c.category_id, c.category_name, photo_filename, COUNT(photo_id) as photo_id
						FROM gallery_category as c
						LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
						GROUP BY c.category_id LIMIT $from, $max_results");
								
if(mysql_num_rows($sql) == 0) {
	echo '<br /><br /><b>No categories have been created yet</b>';
	return;
}

	echo '<table border="1" bordercolor="#FFFFFF" cellspacing="10" cellpadding="5" align="center">';

    while($row = mysql_fetch_assoc($sql)) {
	
if($row['photo_filename'] == 0) {
	$picture = 'No Images<br />';
} else {
	$picture =  '<a href="../gallery/sh_category.php?cid='.$row['category_id'].'"><img src="../'.$images_dir.'/tb_'.$row['photo_filename'].'" border="1"></a><br />';
}
     
if($numcolsprinted == $numcols) { 
	echo "<tr></tr>";
		$numcolsprinted = 0; 
}

	echo '<td width="94" height="130" align="center" valign="top" bordercolor="#000000">'; 
         
	echo ''.$picture.'<a href="../gallery/sh_category.php?cid='.$row['category_id'].'"><br /><b>'.$row['category_name'].'</b></a><br /><br /><font color=\\"#000000\\">'.$row['photo_id'].' images';
                  
	echo '</td>'; 

	$numcolsprinted++;
}

	$colstobalance = $numcols - $numcolsprinted;

	for($i=1; $i<=$colstobalance; $i++) {
} 

	echo "<td></td></table>";

HTH

Sweet, I’ll have to try that out! I guess I was totally off, I was experimenting with a separate query which kinda messed my gallery page up. :stuck_out_tongue: I’ll post back to let you know how it worked out, thanks very much! :slight_smile:

EDIT: I just got it working, thanks again! :smiley:

Hi
I tried this & works a treat, only problem is that the quality of the thumnails is terrible.
Mine are either very blurry or colourless, have I done something wrong?

I’ve got gd 2 running on php 5.

Thanks for any further help:)

Hi,

Replace this line of code:

$destination_handle = ImageCreate($thumbnail_width, $thumbnail_height);

with:

$destination_handle = ImageCreateTrueColor ( $thumbnail_width, $thumbnail_height );

hth

Is there anyway of having greater quality thumbnails? The ones which are generated are decent, but not great.

Thanks!

yes you can. it depends on what your images filetype is.

if it’s .jpg then if you use imagejpeg to make the .jpg it’s default quality is 75. this can be changed:


 imagejpeg ( resource image [, string filename [, int quality]] )
 
 so
 
 imagejpeg ( resource image, string filename ,100 )
 

this only applies for .jpg files as far as i know (so correct me if i’m wrong).

spence.

backtobasics … the answer is below.

Yeah, I took a look at Drews gallery! Thanks anyways!

Thanks matrix; works great :slight_smile:

where is it?


naughty flash games
auto submission

Hi

I’ve been playing around with drewf’s full working gallery system with the added support of resizing the main image if it’s over a certain size (which is great).

Is there anyway possible to add a function to copywrite the main image when the resizing takes place? I’m not to bothered about the thumbnail image.

I’ve read the watermarking tutorial available here but have had no luck getting it to work

Could anyone point me in the right direction pls :stuck_out_tongue:

Many thanks

Hello,
I’ve been working through the tutorial. Is there a way to click on a thumbnail and have an ImageSwap within the same page rather than a full-image view on a new page?
Any help would be appreciated!

Thanks for the tutorial!

Hi,

Do you mean something like this?

[quote=]Hi,

Do you mean something like this?

http://cross-browser.com/toys/img_gallery_2.php[/quote]

Thanks for the reply cosmic_bird. Well, that’s sort of what I am looking for but ideally I’m trying to figure out how to incorporate pulling from the database each thumbnail and showing the larger picture in either a table cell or div all within the same page. I want to keep the thumbnail list available to the left of the image swap area.

Similar to here:
http://www.gr0w.com/articles/imageswapper.php

I’m gone through the code but not quite sure how to assimilate it within the tutorial gallery code.
If you have any (or anyone else) can help - thanks very much!

Lovely tutorial, currently using it.
My dilemma is this …how can I reduce or limit the height and width of the images being uploaded before I move them to my folder from the temp folder. eg 567 by 640.
Any photos bigger than this just stretch and distort the my page.

Thanks

it will be in the upload page.

look for the lines with these in them:


  // Wide Image 
 if($size[0] > $size[1]) 
 {  
  $thumbnail_width = 100;  
  $thumbnail_height = (int)(100 * $size[1] / $size[0]);  
 }  
  
 // Tall Image 
 else 
 { 
   $thumbnail_width = (int)(100 * $size[0] / $size[1]); 
   $thumbnail_height = 100; 
 }
 

just change the witdh and hieght (they are set to 100) to suit your needs.

spence

Hopefully this thread is still available for posting help requests… :shifty:

I’m still working with the tutorial and using Drew’s files he has posted.
I’m getting close to getting the image swapping but my problem is the $final_results being the issue. This string is used for both thumbnails and the final viewing image and I don’t know how to seperate the two.

Attached is simple illustration of what I am trying to achieve. I want to maintain the thumnails along side of the large image.

Since thumbnail results and view full size use the same variable of $result_final and am not able to put each result into their own DIV tag or HTML table/cell. I am able to get my thumbnails into it’s own html table or DIV.

Here’s the code I’m using (and trying) to work with in making the larger image appear on the same page as the thumbnails. Any help with what I need to do is very much appreciated!!

        
        // Thumbnail Listing

        else if( $cid && empty( $pid ) )
        {
                $number_of_thumbs_in_row = 6;

                // 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 = 42;

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

                $result = @mysql_query( "SELECT artwork_id,artwork_caption,artwork_filename FROM gallery_artwork WHERE artwork_category='".addslashes($cid)."' LIMIT $from, $max_results");

                $nr = @mysql_num_rows( $result );

                if( empty( $nr ) )
                {
                        $result_final = "\	<tr><td><div align=\\"center\\"><strong>No images in category found!</strong>
                                                <br><br><font size=\\"2\\"><a href='index.php'>Back to Artwork Gallery Category List</a></font>
                                                </div></td></tr>\
";
                }
                else
                {
                        while( $row = mysql_fetch_array( $result ) )
                        {
                                $result_array[] = "<a href='index.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' cellpadding='0' valign='top' alt='".$row[1]."' /></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 );

                         // $result_final = "<tr><a href='index.php'>Categories</a> > $category_name<br><br>";
        
                        foreach($result_array as $thumbnail_link)
                        {
                                if($counter == $number_of_thumbs_in_row)
                                {        
                                        $counter = 1;
                                        $result_final .= $category_link."\
</tr>\
<tr>\
";
                                }
                                else
                                $counter++;

                                $result_final .= "\	<td><div align=\\"center\\">".$thumbnail_link."</div></td>\
";
                        }
        
                        if($counter)
                        {
                                if($number_of_artwork_in_row)
                        $result_final .= "\	<td colspan='".($number_of_thumbs_in_row)."'></td>\
";
                        $result_final .= "</tr>\
";
                        // Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM gallery_artwork WHERE artwork_category=".addslashes($cid).""),0);

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

if ($total_pages >1)
{  // build links if more than one page


// Build Page Number Hyperlinks
$result_final .=  "<tr><td colspan='".$number_of_thumbs_in_row."'>Showing Page: ".$page.' of '.$total_pages."<br>";


// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    $result_final .=  "\
<a href=\\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$prev\\" title='Previous Page'><< Prev</a>";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        $result_final .= "&nbsp;[$i]";
        } else {
            $result_final .=  "\
<a href=\\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$i\\" title='Page ".$i."'>$i</a>";
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    $result_final .=  "\
<a href=\\"".$_SERVER['PHP_SELF']."?cid=$cid&page=$next\\" title='Next Page'>Next >></a>";
}
$result_final .=  "\
</td></tr>";

}
else
{
$result_final .=  "\
";
}
}
}
}

      // Full Size View of Artwork
     
 else if( $pid )
        {
                $result = mysql_query( "SELECT artwork_caption,artwork_filename FROM gallery_artwork WHERE artwork_id='".addslashes($pid)."'" );
                list($artwork_caption, $artwork_filename) = mysql_fetch_array( $result );
                $nr = mysql_num_rows( $result );
                mysql_free_result( $result );        

                if( empty( $nr ) )
                {
                        $result_final = "\	<tr><td>No Artwork found</td></tr>\
";
                }
                else
                {
                        $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 );        
						
                                                
                        //$result_final .= "<tr>\
\	<td>
                          //                      <a href='index.php'>Categories</a> >
                          //                      <a href='index.php?cid=$cid'>$category_name (Thumbnail Listing)</a></td>\
</tr>\
";

                        $result_final .= "<tr>\
\	<td div id='slide' align='center'>
                                        <br />
                                        <img src='".$images_dir."/".$artwork_filename."' border='0' alt='".$artwork_caption."' />
                                        <br />
                                        </td>
                                        </tr></div>";
                                       
                }
                
        }

Hi, spence_noodle

I am going through your subcategory module, and am having some troubles/errors. from the start.

Here are the returned errors:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/roblisa/public_html/gallery/subcategory2.php on line 30

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/roblisa/public_html/gallery/subcategory2.php on line 30

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/roblisa/public_html/gallery/subcategory2.php on line 71

url: http://robandlisa.ca/gallery/subcategory2.php

I am using your original supplied code (with category_des changed to category_desc):

<?php
include(“config.inc.php”);

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

    // Category Listing

    if( empty($cid) && empty($pid) )
    {
            $number_of_categories_in_row = 1;

            $cat = mysql_query( "SELECT c.category_id,c.category_name,c.category_parent,c.category_desc,COUNT(photo_id)  
                                            FROM gallery_category as c
                                            LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
                                            GROUP BY c.category_id ORDER BY c.category_desc ASC" );        
               
            while( $row = mysql_fetch_array( $cat ) )
            {                        
                if($row[2] == 0)
                {                            
                $cat_array[] = "&lt;font face='Verdana, Arial, Helvetica, sans-serif' size='1'&gt;&lt;a href='cat_user.php?cid=".$row[0]."'&gt;".$row[1]."&lt;/a&gt; "."(".$row[4].")&lt;/font&gt;&lt;br /&gt;";
                }
                
                if($row[2] &gt; 0)
                {
                $subresult = mysql_query("SELECT category_id,category_name,category_parent,category_desc FROM gallery_category WHERE category_name='".$row[1]."' ORDER BY category_desc ASC");
                                                        
                while( $sub_result = mysql_fetch_array( $subresult ) )
                {                                                                                                                                                
                    if ($sub_result[2] !='')
                    {
                        $line1 = explode('/', $sub_result[3]);
                        
                        $line2 = implode(', ', $line1);
                        
                        $words1 = preg_replace('/\\s+/', '', $line2);
                        
                        $words2 = str_replace(',', ' ', $words1);
                                            
                        $level = substr_count($words2," ");
                    
                        if($level == 1)
                        {
                            $add = str_repeat('&nbsp;', 0);
                        }
                        
                        if($level == 2)
                        {
                            $add = str_repeat('&nbsp;', 2);
                        }
                        
                        if($level == 3)
                        {
                            $add = str_repeat('&nbsp;', 4);
                        }
                    
                    $subcat = mysql_query( "SELECT COUNT(photo_id)
                                            FROM gallery_category as c
                                            LEFT JOIN gallery_photos as p ON p.photo_category = '".$sub_result[0]."'
                                            GROUP BY c.category_id ORDER BY c.category_name ASC" );
                    $sub_cat = mysql_fetch_array( $subcat );                        
                    
                    $cat_array[] = "&lt;font face='Verdana, Arial, Helvetica, sans-serif' size='1'&gt;".$add."|-&lt;a href='cat_user.php?cid=".$row[0]."'&gt;".$sub_result[1]."&lt;/a&gt; "."(".$sub_cat[0].")&lt;/font&gt;&lt;br /&gt;";
                        }
                    }
                }
            }
            mysql_free_result( $cat );
            mysql_free_result( $subresult );
            
            foreach($cat_array as $category_link)
            {
                    if($counter == $number_of_categories_in_row)
                    {        
                            $counter = 1;
                    }
                    else
                    $counter++;

                    $cat_final .= "$category_link";
            }

    }

//Final result
echo “$cat_final”;
?>

Here’s what in the category db:

category_id bigint(20)
category_name varchar(50)
category_parent int(11)
category_desc varchar(60)

I am working on making this menu system CSS driven; but, can’t get the backend to fly. Please, assist.