Hey all, I know this is not quite Scratch related, but I live here, so I hope you can put that small fact aside and share your collective knowledge like a colony of ants! Or bees... bees are cool.
Anyhoo, I'm working on a site at the moment, and I need two things, a php script that will choose a random image from a list of possible images when the page is loaded/refreshed and then displays that it on the site. Secondly, I'm looking for a way to run through a set of images in order, using left and right buttons to move through them so that I don't have to create a seperate page for each image.
Thanks in advance for all the help!
p.s. How would that script be edited to display a flash aniamtion instead of an image?
Offline
Use this as a base for the image changer.
http://www.mediafire.com/?l8wjfub8bvveuic
Old project.
Offline
You can still most in misc.
BTW waveOSBeta: the internetometer pic is broken, use this instead:
[url=http://j.mp/98R9zd][img]http://internetometer.com/image/10202.png[/img][/url]
Offline
scimonster wrote:
You can still most in misc.
BTW waveOSBeta: the internetometer pic is broken, use this instead:
Code:
[url=http://j.mp/98R9zd][url]http://internetometer.com/image/10202.png[/url][/url]
It's un-broken now. Must have been a server overload.
Offline
sparks wrote:
Wave, where's the code for changing images in there?
In the html head, I think. Put the img tags in the div's.
Last edited by waveOSBeta (2011-02-17 14:23:52)
Offline
A piece of code from one of my sites...
It displays an image and has buttons for moving forwards and backwards.
Use:
example.com/path/to/file.php?img=(image id).
You need to calculate maxId yourself. Here it was already in the session.
************ is used to hide things for security.
<?php
session_start();
include("************");
mysql_connect($mysql_host,$mysql_user,$mysql_pass);
mysql_select_db("***************");
$query = "SELECT * FROM pictures WHERE ID = '$img'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
extract($row);
$echo = "<table><tr><td><img src=\"{$filepath}\" alt=\"{$caption}\" /></td></tr>\n<tr><td class=\"common\"><p align=\"center\">{$caption}</p></td></tr></table>\n";
switch ($img){
case $maxID :
$back = $img - 1; $forward = 1; break;
case 1 :
$back = $maxID; $forward = 2; break;
default:
$back = $img - 1; $forward = $img + 1; break;
}
?>
<html>
<head>
<title><?php echo $caption ?></title>
<link href="images/icon.ICO" rel="shortcut icon" />
</head>
<body>
<p align="center">
<?php
echo $echo;
?>
</p>
<p align="center"><button onclick="location = 'fullscreen.php?img=<?php echo $back; ?>'"><</button><button onclick="location = 'pictures.php'">Exit</button><button onclick="location = 'fullscreen.php?img=<?php echo $forward; ?>'">></button><p>
</body>
</html>Offline
sparks wrote:
there are three, which one and where?
![]()
There should be 5 divs...
Offline
sparks wrote:
TheSucessor, that looks very neat! I'll have a look at it when I get back in four days
![]()
Anyone have an idea for a random image displayer? Thanks![]()
Javascript. Check out DynamicDrive, it has awesome DHTML and AJAX, Java, (tl;dr removed)
Offline
Here you go:
theImages[0] = '100.jpg'
theImages[1] = '200.jpg'
theImages[2] = '300.jpg'
theImages[3] = '400.jpg'
theImages[4] = '500.jpg'
var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
var whichImg = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImg]+'">');
}Offline
Slight change, maybe?
theImages[0] = '100.jpg'
theImages[1] = '200.jpg'
theImages[2] = '300.jpg'
theImages[3] = '400.jpg'
theImages[4] = '500.jpg'
var p = theImages.length;
function showImage(){
var whichImg = Math.floor(Math.random()*p);
document.getElementById('imagePlace').innerHTML = '<img src="'+theImages[whichImg]+'">'; //IE might not like this bit ;)
/* Uncomment to get automatically changing images
setTimeout('showImage',3000);
*/
}
<div id="imagePlace"></div>Last edited by TheSuccessor (2011-02-18 14:10:33)
Offline
TheSuccessor wrote:
Slight change, maybe?
Code:
theImages[0] = '100.jpg' theImages[1] = '200.jpg' theImages[2] = '300.jpg' theImages[3] = '400.jpg' theImages[4] = '500.jpg' var p = theImages.length; function showImage(){ var whichImg = Math.round(Math.random()*(p-1)); document.getElementById('imagePlace').innerHTML = '<img src="'+theImages[whichImg]+'">'; //IE might not like this bit ;) /* Uncomment to get automatically changing images setTimeout('showImage',3000); */ } <div id="imagePlace"></div>
Thanks!
Offline
Whoops, you might need to requote, I submitted an edit 10 seconds after you posted that
Offline
waveOSBeta wrote:
scimonster wrote:
You can still most in misc.
BTW waveOSBeta: the internetometer pic is broken, use this instead:
Code:
[url=http://j.mp/98R9zd][url]http://internetometer.com/image/10202.png[/url][/url]It's un-broken now. Must have been a server overload.
![]()
It was actually a ] at the end.
Offline