This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-02-17 12:37:35

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

php image displaying?

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?  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#2 2011-02-17 14:04:28

waveOSBeta
Scratcher
Registered: 2009-12-08
Posts: 1000+

Re: php image displaying?

Use this as a base for the image changer.  smile

http://www.mediafire.com/?l8wjfub8bvveuic

Old project.  tongue


http://internetometer.com/image/10202.png]
New signature coming soon!  smile

Offline

 

#3 2011-02-17 14:09:05

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: php image displaying?

You can still most in misc.  roll  BTW waveOSBeta: the internetometer pic is broken, use this instead:

Code:

[url=http://j.mp/98R9zd][img]http://internetometer.com/image/10202.png[/img][/url]

Offline

 

#4 2011-02-17 14:10:19

waveOSBeta
Scratcher
Registered: 2009-12-08
Posts: 1000+

Re: php image displaying?

scimonster wrote:

You can still most in misc.  roll  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.  tongue


http://internetometer.com/image/10202.png]
New signature coming soon!  smile

Offline

 

#5 2011-02-17 14:18:24

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: php image displaying?

Wave, where's the code for changing images in there?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#6 2011-02-17 14:23:30

waveOSBeta
Scratcher
Registered: 2009-12-08
Posts: 1000+

Re: php image displaying?

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)


http://internetometer.com/image/10202.png]
New signature coming soon!  smile

Offline

 

#7 2011-02-17 14:25:26

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: php image displaying?

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.

Code:

<?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; ?>'">&lt;</button><button onclick="location = 'pictures.php'">Exit</button><button onclick="location = 'fullscreen.php?img=<?php echo $forward; ?>'">&gt;</button><p>
</body>
</html>

/* No comment */

Offline

 

#8 2011-02-17 14:25:40

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: php image displaying?

there are three, which one and where?  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#9 2011-02-17 14:27:57

waveOSBeta
Scratcher
Registered: 2009-12-08
Posts: 1000+

Re: php image displaying?

sparks wrote:

there are three, which one and where?  smile

There should be 5 divs...


http://internetometer.com/image/10202.png]
New signature coming soon!  smile

Offline

 

#10 2011-02-17 14:32:14

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: php image displaying?

TheSucessor, that looks very neat! I'll have a look at it when I get back in four days  smile

Anyone have an idea for a random image displayer? Thanks  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#11 2011-02-18 09:16:29

waveOSBeta
Scratcher
Registered: 2009-12-08
Posts: 1000+

Re: php image displaying?

sparks wrote:

TheSucessor, that looks very neat! I'll have a look at it when I get back in four days  smile

Anyone have an idea for a random image displayer? Thanks  smile

Javascript. Check out DynamicDrive, it has awesome DHTML and AJAX, Java, (tl;dr removed)

tongue


http://internetometer.com/image/10202.png]
New signature coming soon!  smile

Offline

 

#12 2011-02-18 10:31:49

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: php image displaying?

Here you go:

Code:

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

 

#13 2011-02-18 14:09:22

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: php image displaying?

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.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)


/* No comment */

Offline

 

#14 2011-02-18 14:10:23

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: php image displaying?

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

 

#15 2011-02-18 14:12:06

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: php image displaying?

Whoops, you might need to requote, I submitted an edit 10 seconds after you posted that  tongue


/* No comment */

Offline

 

#16 2011-02-20 01:56:00

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: php image displaying?

waveOSBeta wrote:

scimonster wrote:

You can still most in misc.  roll  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.  tongue

It was actually a ] at the end.

Offline

 

Board footer