Jump to content

Method Or To Use A Database Instead Of A Directory?


student101

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...