student101 Posted December 6, 2009 Share Posted December 6, 2009 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++; } Link to comment Share on other sites More sharing options...
justsomeguy Posted December 7, 2009 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 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 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 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
Archived
This topic is now archived and is closed to further replies.