| | |
display random images from folder
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
if thats the case, why not generate one more random number ?
This will do.. Don't you think ?
php Syntax (Toggle Plain Text)
<?php $arr=array(); for($i=0;$i<7;$i++){ $arr[$i]="./img/images/".$i.".jpg"; } $random=rand(0,6); $random_1=rand(0,6); echo "<img src=".$arr[$random].">"; echo "<img src=".$arr[$random_1].">"; ?>
This will do.. Don't you think ?
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Dec 2007
Posts: 2
Reputation:
Solved Threads: 0
that looks like it could do the trick with abit of working... basically....
i want there to be a folder of images... the names of those images could be anything at all.... number letters.. mixtures... there will be no logical order to them..... i just need the code to randomly pick say 10 images... out of that folder... no image being displayed twice etc...
if there isnt enough ... say there is 4 images.. it will just display 4
if there is no images... maybe just a statement showing there is no images to display at this time...
i want there to be a folder of images... the names of those images could be anything at all.... number letters.. mixtures... there will be no logical order to them..... i just need the code to randomly pick say 10 images... out of that folder... no image being displayed twice etc...
if there isnt enough ... say there is 4 images.. it will just display 4
if there is no images... maybe just a statement showing there is no images to display at this time...
•
•
Join Date: Mar 2008
Posts: 1
Reputation:
Solved Threads: 0
Hi, I am fairly new to web design and am trying to do exactly what you helped the other person on this post do, is there any way I could also get ahold of that code? I would be very grateful. Thanx.
This is something I just typed up. Not the same as the one I get to the other poster, but close.
It will read a folder and get the images. Then randomize them and display in a paginated form.
It will read a folder and get the images. Then randomize them and display in a paginated form.
PHP Syntax (Toggle Plain Text)
<?php session_start(); $thispage = 'image.php'; $imageDir = 'icons/'; $perPage = 10; //total images to display per page $perRow = 2; //total images per row if ( isset( $_GET['reset'] ) ) { unset( $_SESSION['chunks'] ); } if ( !isset( $_SESSION['chunks'] ) ) { if ( is_dir( $imageDir ) ) { if ( $dir = opendir( $imageDir ) ) { while ( ( $file = readdir( $dir ) ) !== false ) { if ( $file !== '.' && $file !== '..' ) { $images[] = $file; } } closedir( $dir ); } else { die("Unable to read directory - {$imageDir}"); } } shuffle( $images ); $_SESSION['chunks'] = array_chunk( $images,$perPage ); } $page = 1; if ( isset( $_GET['page'] ) && $_GET['page'] > 0 ) { $page = (int) $_GET['page']; } $chunk =& $_SESSION['chunks']; $total = count( $chunk ); if ( isset( $chunk[$page-1] ) ) { $images = $chunk[$page-1]; $html = "<table cellspacing=\"0\" cellpadding=\"3\">\n\t<tr>\n"; $i = 0; foreach( $images as $image ) { if ( $i == $perRow ) { $html .= "\t</tr>\n\t<tr>\n"; $i = 0; } $html .= "\t\t<td><img src=\"{$imageDir}{$image}\" /></td>\n"; $i++; } $html .= "\t<tr>\n"; if ( $total > 1 ) { $nav = ''; if ( $page > 1 ) { $nav .= "<a href=\"{$thispage}?page=1\">[FIRST]</a><a href=\"{$thispage}?page=" . ( $page - 1 ) . "\">[PREV]</a>"; } $i = 1; while( $i < $total + 1 ) { $nav .= "<a href=\"{$thispage}?page={$i}\">[{$i}]</a>"; $i++; } if ( $page < $total ) { $nav .= "<a href=\"{$thispage}?page=" . ( $page + 1 ) . "\">[NEXT]</a><a href=\"{$thispage}?page={$total}\">[LAST]</a>"; } $html .= "\t<tr>\n\t\t<td colspan=\"{$perRow}\">{$nav}</td>\n\t</tr>\n"; } $html .= "</table><br /><br /><a href=\"{$thispage}?reset=true\">Shuffle Images</a>"; echo $html; } ?>
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 0
0
#17 Oct 21st, 2009
Hi..kkeith29
How can we make the image click able ?
wrt line 48 in your code
I tried
But I got error..
can you please help me to make the images displayed clickable in this format
mysite.com/?v={$image}
Thanks
How can we make the image click able ?
wrt line 48 in your code
PHP Syntax (Toggle Plain Text)
$html .= "\t\t<td><img src=\"{$imageDir}{$image}\" /></td>\n";
PHP Syntax (Toggle Plain Text)
$html .= "\t\t<td><a href="MYSITE.com/?v={$image}"<img src=\"{$imageDir}{$image}\" /></td>\n";
But I got error..
can you please help me to make the images displayed clickable in this format
mysite.com/?v={$image}
Thanks
Last edited by poison23; Oct 21st, 2009 at 2:42 pm.
0
#18 Oct 21st, 2009
Replace
with
PHP Syntax (Toggle Plain Text)
$html .= "\t\t<td><img src=\"{$imageDir}{$image}\" /></td>\n";
PHP Syntax (Toggle Plain Text)
$html .= "\t\t<td><a href=\"http://www.mysite.com/?v={$image}\"><img src=\"{$imageDir}{$image}\" /></a></td>\n";
Google is your friend.
Use [code] tags.
If you have found a solution to your problem, please mark the thread as SOLVED.
Use [code] tags.
If you have found a solution to your problem, please mark the thread as SOLVED.
![]() |
Similar Threads
- Random Images on Refresh (JavaScript / DHTML / AJAX)
- random images (PHP)
- Implementing Random Images (Java)
- Need help making simple random images (PHP)
- ASP .NET Display Random records from the database (ASP.NET)
- looking for a free or low cost program to randomly display text and/or images (PHP)
Other Threads in the PHP Forum
- Previous Thread: ajax observeField in CakePHP
- Next Thread: Help me in form validation
| Thread Tools | Search this Thread |
animation api applet array back backup bmp broken button byte clone cloning code delete directory disk displayimageinsteadofflash drive dynamic file flash function gdi generator ghost google hard header hosting image images java jpanel jpeg link loops matrix mediawiki method multimedia mysql number open panel php picture picturebox problem python random reading reputationmanagement screen scroll search shot subdomain swf swf. swing transfer upload url web website whileloop windows







