AdRock Posted August 26, 2006 Share Posted August 26, 2006 I wanted a really simple image gallery but all the ones i found were too complicated with admin areas and stuff that has no use for me.Then I found some code which uses html and css to create the image gallery but the code could end up being repetitive and long so am wandering if there is soimething that can be one in php to make the code shorterHere is a small part of the code whcih would display four images on one row. Imagine if you had ten rows and how mmuch code that would take.[code]<a class="thumbnail" href="#"><img src="gallery/jack002_thumb.jpg" width="100px" height="75px" border="0" /><span><img src="gallery/jack002.jpg" /></span></a><a class="thumbnail" href="#"><img src="gallery/jack001_thumb.jpg" width="100px" height="75px" border="0" /><span><img src="gallery/jack001.jpg" /></span></a><a class="thumbnail" href="#"><img src="gallery/jack003_thumb.jpg" width="100px" height="75px" border="0" /><span><img src="gallery/jack003.jpg" /></span></a><a class="thumbnail" href="#"><img src="gallery/jack004_thumb.jpg" width="100px" height="75px" border="0" /><span><img src="gallery/jack004.jpg" /></span></a><a class="thumbnail" href="#"><img src="gallery/jack005_thumb.jpg" width="100px" height="75px" border="0" /><span><img src="gallery/jack005.jpg" /></span></a> <br />[/code]Is there something that could do this as many times as needed...probably ten? Quote Link to comment Share on other sites More sharing options...
tomfmason Posted August 26, 2006 Share Posted August 26, 2006 I would do this one of two ways.I would ether store the names of the images in a database table then use mysql_fetch_assoc/array to display them or you could, if you only have the gallery images it that dir, [code=php:0]readdir[/code]like this[code]<?phpif ($handle = opendir('path/to/gallery')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo "<a class=\"thumbnail\" href=\"#\"><img src=\"gallery/$file\" width=\"100px\" height=\"75px\" border=\"0\" /><span>"; } } closedir($handle);}?>[/code]You may want to refine this code a bit. It should give you a basic ideaGood luck,Tom Quote Link to comment Share on other sites More sharing options...
AdRock Posted August 26, 2006 Author Share Posted August 26, 2006 Yeah...storing image name in the database is what i doHow would i display 4 images at a time using mysql_fetch_accoc/array?I've only ever displayed one at a time when pulling stuff out Quote Link to comment Share on other sites More sharing options...
Barand Posted August 26, 2006 Share Posted August 26, 2006 see (table method)http://www.phpfreaks.com/forums/index.php/topic,105762.msg422600.html#msg422600and here's a css method[code]<?phpinclude 'db.php';?><html><head><meta name="generator" content="PhpED Version 4.5 (Build 4513)"><title>CSS example</title><meta name="author" content="Barand"><STYLE type='text/css'>DIV.item { width: 150px; height: 150px; border: 1px solid silver; margin: 5px; text-align: center; padding; 5px; float: left;}BR { clear: both;}</STYLE></head><body> <DIV> <?php $sql = "SELECT a, b FROM tablename ORDER BY a, b"; $res = mysql_query($sql); $count=0; while (list($a, $b) = mysql_fetch_row($res)) { echo "<DIV class='item'>$a<br>$b</DIV>"; if (++$count % 4 == 0) echo '<br>'; } ?> </DIV></body></html> [/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.