student101 Posted December 6, 2009 Report Share Posted December 6, 2009 (edited) Looking for a method or way to code this to use a database instead of a directory? function returnimages($dirname="uploads") { $pattern="\.(jpg|jpeg|png|gif|bmp)$"; $files = array(); $i = 0; if($handle = opendir($dirname)) { while(false !== ($file = readdir($handle))){ if(eregi($pattern, $file)){ if($i>0){ echo ","; } echo("'$dirname/$file'\n"); $i++; } } closedir($handle); } return($files); } returnimages(); Something like this?? $file = $row['image'];$dirname="uploads";$i = 0;while ($i <= 10) {if($i>0){ echo ","; } // how to loop next image here?echo("'$dirname/$file'\n"); $i++; } Edited December 6, 2009 by student101 Link to comment Share on other sites More sharing options...
justsomeguy Posted December 7, 2009 Report Share Posted December 7, 2009 Do you have a database with the tables and records in it? Link to comment Share on other sites More sharing options...
student101 Posted December 7, 2009 Author Report Share Posted December 7, 2009 Do you have a database with the tables and records in it? Album: CREATE TABLE `album_alb` ( `id_alb` INT(11) NOT NULL AUTO_INCREMENT, `title_alb` VARCHAR(100) NOT NULL, `description_alb` VARCHAR(255) NOT NULL, `thumb` VARCHAR(255) NULL DEFAULT NULL, `imagename` VARCHAR(255) NULL DEFAULT NULL, `date_alb` VARCHAR(30) NULL DEFAULT NULL, `showhome` VARCHAR(1) NULL DEFAULT NULL, PRIMARY KEY (`id_alb`), INDEX `title_alb` (`title_alb`))COLLATE=utf8_general_ciENGINE=InnoDBROW_FORMAT=COMPACTAUTO_INCREMENT=41AVG_ROW_LENGTH=2048 The albums images: CREATE TABLE `album_img` ( `id_img` INT(11) NOT NULL AUTO_INCREMENT, `idalb_img` INT(11) NOT NULL DEFAULT '0', `thmimage` VARCHAR(100) NULL DEFAULT NULL, `lrgimage` VARCHAR(100) NULL DEFAULT NULL, `description_img` VARCHAR(50) NOT NULL, `date_img` VARCHAR(30) NULL DEFAULT NULL, `showhome` VARCHAR(1) NULL DEFAULT NULL, PRIMARY KEY (`id_img`), INDEX `idalb_img` (`idalb_img`), CONSTRAINT `album_img_ibfk_1` FOREIGN KEY (`idalb_img`) REFERENCES `album_alb` (`id_alb`) ON UPDATE CASCADE ON DELETE CASCADE)COLLATE=utf8_general_ciENGINE=InnoDBROW_FORMAT=COMPACTAUTO_INCREMENT=40AVG_ROW_LENGTH=2048 Link to comment Share on other sites More sharing options...
justsomeguy Posted December 7, 2009 Report Share Posted December 7, 2009 You can use a select query to get the results from the database and loop through them. Check the PHP tutorials for examples of using a database. Link to comment Share on other sites More sharing options...
student101 Posted December 7, 2009 Author Report Share Posted December 7, 2009 You can use a select query to get the results from the database and loop through them. Check the PHP tutorials for examples of using a database.yes, very able to do that, which will defeat the purpose of my first question.One of my odd moments again I guess, asking questions that I've answered before.Tthanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now