Welcome to TalkGraphics.com
Page 1 of 2 12 LastLast
Results 1 to 10 of 25

Hybrid View

  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
    Sep 2000
    Location
    London, UK
    Posts
    1,436

    Default Re: php image-gallery

    Hi

    Would this help: http://www.sitepoint.com/article/php...system-minutes ?

    If your folder structure is say:

    pictures
    - 123.jpg
    - 124.jpg
    php
    - gallery.php

    Then gallery.php must echo with ../pictures/ and then the filename.
    Simon
    ------------------------------
    www.tlaconsultancy.co.uk
    www.bricksandbrass.co.uk

  8. #8
    Join Date
    Oct 2005
    Location
    Prague, Czech Republic
    Posts
    231

    Default Re: php image-gallery

    HTML Code:
    echo "\n\t\t<a href=\"purePHP.php?\$galleryid=$GID\">$name</a><br />";
    These links don't work as expected, am I correct?

    "$" symbol is not used in query string variable names but you use "\$galleryid". That won't work Try changing it to this:
    HTML Code:
    echo "\n\t\t<a href=\"purePHP.php?galleryid=$GID\">$name</a><br />";
    And you may also need to change this MySQL query (depends on your PHP configuration):
    HTML Code:
    $query2 = mysql_query("SELECT * FROM image WHERE GID = '$galleryid'");
    to
    HTML Code:
    $query2 = mysql_query("SELECT * FROM image WHERE GID = '".$_GET['galleryid']."'");

  9. #9
    Join Date
    Jan 2006
    Posts
    2,439

    Default Re: php image-gallery

    Hi Suvek,

    that's insecure code:
    Quote Originally Posted by Suvek View Post
    HTML Code:
    $query2 = mysql_query("SELECT * FROM image WHERE GID = '".$_GET['galleryid']."'");
    Such a code is open to SQL injections, please don't do that.

    see also: Wikipedia article about SQL injection

    Remi

  10. #10
    Join Date
    Oct 2005
    Location
    Prague, Czech Republic
    Posts
    231

    Default Re: php image-gallery

    Quote Originally Posted by remi View Post
    code is open to SQL injections, please don't do that.
    Remi
    Right, I should have mentioned that Thanks
    But to make it clear (well it is probably obvious ) - SQL injection is a threat in both code versions - doesn't matter if you access that GET var as $galleryid or $_GET['galleryid']. My original point that $galleryid may not work directly remains the same.

 

 

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
  •