Welcome to TalkGraphics.com
Page 1 of 3 123 LastLast
Results 1 to 10 of 25
  1. #1
    Join Date
    Aug 2006
    Posts
    73

    Question php image-gallery

    ok,
    so I'm working on my new homepage, and I decided I'd replace the Expose flash-gallery I'd make my own gallery, to have the page completly 'homemade'...
    Though my knownledge on php isn't too good, I started, and I think I've gotten quite far, now what I'm struggeling with is a category menu at the top, so that I can organize my pictures into categories, without having to make a new html document for each category...

    This is how far I've gotten:
    Code:
    <?php
    
    class Gallery {
    
    var $userstable = "gallery";
    var $result;
    
    function DoGallery(){
    
    mysql_connect('localhost','root','')
    || die(mysql_error());
    @mysql_select_db('thorbear')
    || die("Unable to select database");
    
    if(!isset($_GET['userstable'])) $notgallery = "notgallery";
    	echo '<a href="?userstable='.$notgallery.'"> category </a>';
    
    $query = "SELECT * FROM $this->userstable";
    $this->result = mysql_query($query);
    $number = mysql_num_rows($this->result);
    $i = 0;
    if ($number == 0) :
    	print "<center><b>No Images? O.o</b></center>";
    elseif ($number > 0) :
    	while ($i < $number):
    		$path = mysql_result($this->result,$i,"path");
    		$thumb = mysql_result($this->result,$i,"thumb");
            $alt = mysql_result($this->result,$i,"alt");
    		print	"<div class=\"img\">";
    		print	"<a href=\"$path\" target=\"_new\">";
    		print	"<img src=\"$thumb\" alt=\"$alt\" width=\"110\" height=\"90\" style=\"-moz-opacity:0.4;filter:alpha(opacity=40)\" onmouseover=\"this.style.MozOpacity=1;this.filters.alpha.opacity=100\" onmouseout=\"this.style.MozOpacity=0.4;this.filters.alpha.opacity=40\" />";
    		print	"</a>";
    		print	"<div class=\"desc\">$alt</div>";
    		print	"</div>";
            $i++;
    	endwhile;
    endif;
    
    mysql_free_result($this->result);
    mysql_close();
    
    }
    }
    
    $p_obj =& new Gallery;
    $p_obj->DoGallery();
    
    ?>
    the images show properly, just the way I want them to, but I can't make the menu work...any tips? (other improvements are accepted with thx )

    thx in advance

  2. #2
    Join Date
    Nov 2004
    Location
    Israel
    Posts
    2,538

    Default Re: php image-gallery

    Manwe, I cannot help you with the code but I can give you some links to free php galleries, perhaps you can play around and see what you need from there.

  3. #3
    Join Date
    Aug 2006
    Posts
    73

    Default Re: php image-gallery

    Quote Originally Posted by Availor View Post
    Manwe, I cannot help you with the code but I can give you some links to free php galleries, perhaps you can play around and see what you need from there.
    nah, i have some of those, they aren't too helpful, cuz i know too little about php, and they're usually made to fit with everything...
    I'd prefer some more direct help...
    but thx anyway

  4. #4
    Join Date
    Sep 2000
    Location
    London, UK
    Posts
    1,436

    Default Re: php image-gallery

    Hi

    It looks as if you have only one table - 'gallery' - when really you need two - one would be called 'gallery' and the other 'image'. So each image has a foreign key 'galleryid' to link it back to the 'gallery'. The 'gallery' table would give you the gallery names.

    So you then have two chunks of php - one to deliver the names of the galleries, and a second to get the images for the selected gallery.
    Simon
    ------------------------------
    www.tlaconsultancy.co.uk
    www.bricksandbrass.co.uk

  5. #5
    Join Date
    Aug 2006
    Posts
    73

    Default Re: php image-gallery

    Sounds fair
    but I'm not sure if I understood you 100%

    1: the two tables, 1 for each image and 1 for the gallery...but I didn't quite get the reason for it...

    2: the two php pieces, that is what I've attempted, but obviously not succeded

    maybe you could make a very simple example? (VERY simple, just to kick me off in the right direction )

    PS. I was planning to work on this today and look closer on ur tip, but I've had as much as 10 min by the comp until now, and now it's 11pm...I'll look closer onto it tomorrow, maybe I'll understand it better then...

  6. #6
    Join Date
    Sep 2000
    Location
    London, UK
    Posts
    1,436

    Default Re: php image-gallery

    Hi

    I've attached a diagram...

    The first script, gallerylist.php, gets the gallery data from the gallery table and creates the menu. Each entry in the list is an <a href=...> calling the showimage.php script and passing to it the galleryid.

    The showimage.php script can now do a query to get the data for the images in that gallery.

    Why use two tables? Because a) it is good practice and b) because with a single table the gallery data has to be stored for every image which means that updating it becomes unecessarily complicated.

    For an example of how it looks, try http://www.theeventsbusiness.com/gallerylist.php
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	gallery.gif 
Views:	523 
Size:	13.0 KB 
ID:	41116  
    Simon
    ------------------------------
    www.tlaconsultancy.co.uk
    www.bricksandbrass.co.uk

  7. #7
    Join Date
    Aug 2006
    Posts
    73

    Default Re: php image-gallery

    Thanks
    I'll look into it as soon as i have time and motivation, and I'll post the finished thing here

  8. #8
    Join Date
    Oct 2006
    Location
    UK
    Posts
    216

    Default Re: php image-gallery

    i wish i could understand this stuff

  9. #9
    Join Date
    Sep 2000
    Location
    London, UK
    Posts
    1,436

    Default Re: php image-gallery

    !!!

    We all started there! I have been doing 'data analysis' since I started my working life - it was the first technique I got taught. If you google 'normalisation' you will get a load of heavy stuff, but fundamentally you need to work out what a business, process or requirement needs in terms of data - what things is it interested in? It might be customers, orders, products, order lines, ... or galleries and images. You make sure that each thing really is just one thing - it's no good having an order which has several order lines in it - because how many do you need? And how do you refer in a program to each one? Or have order line and put all the order data on every one of them - which wastes space in a database, and can become out of sync - if the customer moves, you have to change all the addresses in all the order lines.

    Once you have a good data structure... the programming in PHP or whatever is basically simple! But that's another story...
    Simon
    ------------------------------
    www.tlaconsultancy.co.uk
    www.bricksandbrass.co.uk

  10. #10
    Join Date
    Aug 2006
    Posts
    73

    Default Re: php image-gallery

    oh!...OOOH! I've had a revelation!
    (I know, it took some time) I haven't looked at this for months, I sort of gave it up, decided to wait with it untill I had learned enough to make it...
    In the meantime I've been having IT at school, there we've been learning (incredebally enough, with our teacher) about databases, I thought I knew almost all that was to know about databases and how to set them up...

    Anyway, seems I misunderstood you last time I read over this, when you said "Two tables" I though you meant HTML tables (yes I still use those), which explains why I didn't understand at all what you were talking about

    I'll start off with this right away

 

 

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
  •