Current location: Hot Scripts Forums » General Community » Script Requests » Image display


Image display

Reply
  #1 (permalink)  
Old 06-30-09, 05:47 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
Image display

Hi there..

I'm looking for a script to manage this:

I got a folder with f.e. 10 images from 100x100px
In a div I display picture 1. Now I want to fade to the
next picture from the folder in that div.. and than the next... and so on.

When I came to the end of the image list it should start with picture 1 again.
i can make this i flash but I think javascript is better for the visitors of my site.

Who can help me out here a bit?.

_j
Reply With Quote
  #2 (permalink)  
Old 06-30-09, 11:13 AM
Boraan's Avatar
Boraan Boraan is offline
Coding Addict
 
Join Date: Jul 2007
Location: Clayton, NC
Posts: 292
Thanks: 0
Thanked 1 Time in 1 Post
it sounds complicated but it's not. The answer is a loop. I'm a perl dev here so bear with me. I'd build a script like so... (bear with me here this is coming off the top of my head on the fly).

First I'd create a database to manage those images. Using unix shell commands you can upload/remove images and just store the names in the database. For example my database would be set up like this:

id (auto_increment)
image_name (full name with extention like image.gif, image2.jpg, image3.png - it'll save you from having to use a custom perl parser and works well with uploading).
basedir (in apache my directories are set up like this - /usr/local/apache/htdocs/images/yourfoldername)
date (datetime) - useful for gallery scripts where you have dated display

Once the database is set up, I would let perl do all the work including counts and printing.

Code:
#!/usr/bin/perl
use strict;

print "Content-type/html\n\n";

my $count = 1;
# Set a default base to start counting for a loop. Perl counts 0 as a number so if you had 1o items
# 0 1 2 3 4 5 6 7 8 9, so I set it to 1 as default (1 2 3 4 5 6 7 8 9 10).

my($dbh,$sth,$rv,$f);
# Connect to the database
our $dbh = DBI->connect("dbi:mysql:$dbname", "root", "password") or &dienice("Can't connect to database: $DBI::errstr"); ## I have a &dienice subroutine

# retrieve the database informaion.
$sth = $dbh->prepare("select *,date_format(date, '%c/%e/%Y') as nicedate from images order by date desc") or &dbdie;

## Desc - descending order. the other option is asc (ascending).
## date_format(date, '%c/%e/%Y') shows date as 1/1/2009. if you want the time in AM or PM change it to
## date_format(date, '%c/%e/%Y %r')
$rv = $sth->execute;

# use a while loop
while ($f = $sth->fetchrow_hashref) {

# define what variables you want to display.
my($image-name) = "$f->{image_name}";
# You'll notice that I used a hyphen (-) instead of an underscore (_). This is to avoid accidental
# syntax errors. Underscores are not a named character and must be backlashed, so a hypen works well.
my($nicedate) = "$f->{nicedate}";
my($basedir) = "$f->{basedir}";

#define a qualified path.
my($fullpath) = "$basedir\/$image-name";

# this is where you print the images how you want them to display. I use print <<NAME so that I don't have to backslash non-named characters. You can also use the CGI mod (use CGI) but it's not entirely necessary).
print <<EndHTML;
<img src="$fullpatth" border="0" width="100" height="100"><br>
Name: $image-name Date: $nicedate
EndHTML
}
loop only work from start to finish while it's true. once you reach the end of the loop you have to initate a start point. so back in your code under the EndHTML you'd put this.

Code:
# Get the count of entries in the database.
my $count_sth = $dbh->prepare("SELECT COUNT(*) FROM images");
$count_sth->execute;
# Your total count would be $count_sth->fetchrow;
# so now you use your default count start and set it to new loop just to print the start.
my @start = ("$count" + ... +" $count_sth->feathrow");

# If you had 10 images for example it would show like this. (1...10)
# to print the first number in the loop you use perl you'd use loop option.
my $first = shift(@start); # will return 1 as the first number
my $last = pop(@start); # will return 10 as the last number

# that counts all of the entries in your image database using 1 as the start.
# when the loop reaches the end you print the first number as a link or automatically redirect to the first.

$sth = $dbh->prepare("select *,date_format(date, '%c/%e/%Y') as nicedate from images order by date desc start $first") or &dbdie;

# that restarts the loop with the first number. all you have to new is print it or auto redirect back to the start.
}
The other, faster option is to do the select count first and make the whole select process a subroutine and after the loop refer back to the subroutine. It's an infinite count if you do that though, so be careful. non-terminating script will blister your server.

If you need to see a whole working version I can build it for you and let you see. I know I talked alot of code and wrote what seems like alot, but that would have taken me 5 minutes at best.

[/code]
__________________
Dexter Nelson
Techdex Development & Solutions
========================
Internet Marketing For Programmers | Free Market Research in 15 Minutes or Less
My Software: Hotscripts Softpedia software.techdex.net

Last edited by Boraan; 06-30-09 at 11:14 AM. Reason: fixing syntax
Reply With Quote
  #3 (permalink)  
Old 07-01-09, 03:43 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Boraan,

thnx! but perl is complete new to me.. so it sound more difficult to me..
I'm used to work with php, html and javascript.

I'll "dive" into your answer and try to figure it out..

_j
Reply With Quote
  #4 (permalink)  
Old 07-01-09, 08:26 AM
Boraan's Avatar
Boraan Boraan is offline
Coding Addict
 
Join Date: Jul 2007
Location: Clayton, NC
Posts: 292
Thanks: 0
Thanked 1 Time in 1 Post
Ahh. you didn't say it was php. The script above is incomplete. I wrote the script as I went to be more of a guildeline. if you need it done in php there are several on the boards that can either point you to the right direction or build it for you.
__________________
Dexter Nelson
Techdex Development & Solutions
========================
Internet Marketing For Programmers | Free Market Research in 15 Minutes or Less
My Software: Hotscripts Softpedia software.techdex.net
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP & MYSQL Same Table Ishmell PHP 7 06-28-09 11:36 PM
div css theighost CSS 11 09-14-08 02:30 AM
Selecting image to display via asp form Anessa ASP 3 08-25-05 08:32 AM
Image display based on URL rjwebgraphix PHP 5 09-09-04 08:02 AM


All times are GMT -5. The time now is 09:28 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.