Results 1 to 5 of 5

Thread: Method or way to use a database instead of a directory?

  1. #1
    Join Date
    Feb 2008
    Posts
    137
    Thanks
    18
    Thanked 2 Times in 2 Posts

    Question Method or way to use a database instead of a directory?

    Looking for a method or way to code this to use a database instead of a directory?
    PHP Code:
    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??
    PHP Code:
    $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++;  

    ASCII stupid question, get a stupid ANSI!
    Beta is Latin for still doesn’t work.
    Mac users swear by their Mac, PC users swear at their PC.
    Keyboard not found...Press any key to continue.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    What kind of database are you using? Can you tell us what the column names are you're using?

  3. #3
    Join Date
    Feb 2008
    Posts
    137
    Thanks
    18
    Thanked 2 Times in 2 Posts

    Default

    Quote Originally Posted by bluewalrus View Post
    What kind of database are you using? Can you tell us what the column names are you're using?
    Sorry totally forgot about that, it's MySQL.
    Code:
    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_ci
    ENGINE=InnoDB
    ROW_FORMAT=COMPACT
    AUTO_INCREMENT=41
    AVG_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_ci
    ENGINE=InnoDB
    ROW_FORMAT=COMPACT
    AUTO_INCREMENT=40
    AVG_ROW_LENGTH=2048
    ASCII stupid question, get a stupid ANSI!
    Beta is Latin for still doesn’t work.
    Mac users swear by their Mac, PC users swear at their PC.
    Keyboard not found...Press any key to continue.

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Something like this but I don't use mysql I use mssql so will need some altering, also not sure the relation between the two tables you've posted the code for. This code will pull names, locations, captions, the id, and display all of them as images if you want to limit it to a select number you can use top 10 or something. There's a lot of ways you could go...

    PHP Code:
    <?php
    $tsql 
    "Select ID, PHOTO, CAPTION, LOCATION From photo_info";
    include 
    'DBConnection.php';
    $stmt sqlsrv_query$conn$tsql);
    if( 
    $stmt === false) {
        echo 
    "Error in statement preparation/execution.\n";
        die( 
    print_rsqlsrv_errors(), true));
        }
        
    $increase "0";
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    </head>
    <body>
    <?php 
        
    while (sqlsrv_fetch$stmt )) {
            
    $id[] =  sqlsrv_get_field$stmt0);
            
    $photo[] = sqlsrv_get_field$stmt1SQLSRV_PHPTYPE_STRINGSQLSRV_ENC_CHAR));
            
    $caption[] = sqlsrv_get_field$stmt2SQLSRV_PHPTYPE_STRINGSQLSRV_ENC_CHAR));
            
    $location[] = sqlsrv_get_field$stmt3SQLSRV_PHPTYPE_STRINGSQLSRV_ENC_CHAR));
            echo 
    "<img src=\"$location[$increase]/$photo[$increase]\" alt=\"$caption[$increase]\" /> Figure # $id[$increase] <br />\n";
            
    $increase++;
        }
         
    sqlsrv_free_stmt$stmt);
        
    sqlsrv_close$conn);
        
    ?>
    </body>
    </html>

  5. The Following User Says Thank You to bluewalrus For This Useful Post:

    student101 (12-08-2009)

  6. #5
    Join Date
    Feb 2008
    Posts
    137
    Thanks
    18
    Thanked 2 Times in 2 Posts

    Default

    Thank you.
    ASCII stupid question, get a stupid ANSI!
    Beta is Latin for still doesn’t work.
    Mac users swear by their Mac, PC users swear at their PC.
    Keyboard not found...Press any key to continue.

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
  •