Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Web Coding

Reply
 
LinkBack Thread Tools
Old 04-10-08   #1 (permalink)
4 gigs of hert
 
Kopi's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Hamilton Ontario
Posts: 7,270

Rep: 459 Kopi is a proven memberKopi is a proven memberKopi is a proven memberKopi is a proven memberKopi is a proven member
Unique Rep: 303
Trader Rating: 17
Default Random Pictures in HTML/PHP

Say I have 4 or 5 pictures I'd like to have randomly loaded when someone accesses a website. Is there any way to make it so that everytime the site is loaded a different picture is loaded as well?
__________________
Quote:
Originally Posted by FlaKing View Post
I noticed it when everybody started to use it to describe "300". Afterwards, everything became "epic". Epic fail, shoes, mouse, laptop, mom, El Camino, Sebring, paper towel, etc.

System: Kopisaurus
CPU
Intel e8400 Q810A198 @4ghz 1.368v
Motherboard
ASUS P5K Premium Black Pearl
Memory
2x2gb Mushkin Ascent 1066mhz
Graphics Card
XFX 8800gt Alpha Dog 512mb w/ TT DuOrb
Hard Drive
160gb WD / 250gb Barracuda
Sound Card
Creative SoundBlaster Audigy SE 7.1
Power Supply
OCz GameXstream 700w
Case
NZXT Trinity
CPU cooling
Noctu NH-U12P w/YL D12SH 88cfm
GPU cooling
Thermaltake DuOrb
OS
Windows Vista Ultimate 64bit
Monitor
LG Flatron 22" ws 3000:1 - 2ms
Kopi is offline Overclocked Account   Reply With Quote
Old 04-10-08   #2 (permalink)
iRun
 
Chipp's Avatar
 
intel ati

Join Date: Dec 2004
Posts: 13,440
Blog Entries: 28

FAQs Submitted: 18
Folding Team Rank: 179
Team Name: Rough Riders
Hardware Reviews: 3
Trader Rating: 8
Default

On my site I use this code:

Code:
<img src="http://site/images/<?php echo(rand(1,3)); ?>.jpg"
width="600" height="100" alt="logo" />
See the little PHP bit in the middle? That is set up so that when it generates a random number (between 1 and 3 in my case), the number becomes the name of my image file. Thus, if you name your images a number you can use the random number generator to select the image for you. Of course you'd want to edit the image properties to whatever size you need (or just remove them if the images are different sizes).

I doubt this is the politically correct way, but it gets the job done. I'm still teaching myself PHP so I don't know if it's "proper".

System: Linux exclusive? I think so.
CPU
Intel E2160 @ 3.1ghz (Summer OC)
Motherboard
Abit IP35-E
Memory
2x1gb OCZ Plat Rev. 2 DDR2
Graphics Card
ATI X1900XT
Hard Drive
120gb Hitatchi Deskstar IDE
Sound Card
Onboard -> AVR210 as DAC (X-Fi + linux = bad)
Power Supply
CoolerMaster RM-500
Case
CoolerMaster Centruion 5
CPU cooling
Ultra90 (lapped) and Sanyo Denki 92mm
GPU cooling
Zalman VF900
OS
ArchLinux x64
Monitor
Viewsonic VE175b

Last edited by Chipp : 04-10-08 at 08:08 PM.
Chipp is offline I fold for Overclock.net Overclocked Account Chipp's Gallery   Reply With Quote
Old 04-10-08   #3 (permalink)
4 gigs of hert
 
Kopi's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Hamilton Ontario
Posts: 7,270

Rep: 459 Kopi is a proven memberKopi is a proven memberKopi is a proven memberKopi is a proven memberKopi is a proven member
Unique Rep: 303
Trader Rating: 17
Default

Thanks alot Chip, time for some experimenting!

Lets say my images are named

kopi
kops
kopo

They are all different sizes, and I'd like to alternate between them. Would the code be

Code:
<img src="http://site/images/<?php echo(rand(1,3)); ?>.jpg"/>
And the images would simply be in the images directory?
__________________
Quote:
Originally Posted by FlaKing View Post
I noticed it when everybody started to use it to describe "300". Afterwards, everything became "epic". Epic fail, shoes, mouse, laptop, mom, El Camino, Sebring, paper towel, etc.

System: Kopisaurus
CPU
Intel e8400 Q810A198 @4ghz 1.368v
Motherboard
ASUS P5K Premium Black Pearl
Memory
2x2gb Mushkin Ascent 1066mhz
Graphics Card
XFX 8800gt Alpha Dog 512mb w/ TT DuOrb
Hard Drive
160gb WD / 250gb Barracuda
Sound Card
Creative SoundBlaster Audigy SE 7.1
Power Supply
OCz GameXstream 700w
Case
NZXT Trinity
CPU cooling
Noctu NH-U12P w/YL D12SH 88cfm
GPU cooling
Thermaltake DuOrb
OS
Windows Vista Ultimate 64bit
Monitor
LG Flatron 22" ws 3000:1 - 2ms
Kopi is offline Overclocked Account   Reply With Quote
Old 04-10-08   #4 (permalink)
iRun
 
Chipp's Avatar
 
intel ati

Join Date: Dec 2004
Posts: 13,440
Blog Entries: 28

FAQs Submitted: 18
Folding Team Rank: 179
Team Name: Rough Riders
Hardware Reviews: 3
Trader Rating: 8
Default

No, that would not work.

The "echo" command inserts the number generated by the math function (rand) as the file name. Thus, your files would have to be names 1.jpg, 2.jpg, 3.jpg, etc, etc. Basically, once the php script is finished executing the resulting HTML would look like this:
Code:
 <img src="http://site/images/2.jpg" />
In that case, "2" would have been the output from the random selector. Does that make sense?

System: Linux exclusive? I think so.
CPU
Intel E2160 @ 3.1ghz (Summer OC)
Motherboard
Abit IP35-E
Memory
2x1gb OCZ Plat Rev. 2 DDR2
Graphics Card
ATI X1900XT
Hard Drive
120gb Hitatchi Deskstar IDE
Sound Card
Onboard -> AVR210 as DAC (X-Fi + linux = bad)
Power Supply
CoolerMaster RM-500
Case
CoolerMaster Centruion 5
CPU cooling
Ultra90 (lapped) and Sanyo Denki 92mm
GPU cooling
Zalman VF900
OS
ArchLinux x64
Monitor
Viewsonic VE175b
Chipp is offline I fold for Overclock.net Overclocked Account Chipp's Gallery   Reply With Quote
Old 04-10-08   #5 (permalink)
Audiophile
 
Higgins's Avatar
 
amd ati

Join Date: Dec 2005
Location: The Burbs of Detroit City
Posts: 3,199

Rep: 227 Higgins is acknowledged by manyHiggins is acknowledged by manyHiggins is acknowledged by many
Unique Rep: 184
Hardware Reviews: 4
Trader Rating: 2
Default

Kopi, Chipp means renaming the pictures with numbers as names (1,2, & 3 for example) so with that PHP code chosing a random number within say 1 - 3 and having 3 jpgs all renamed to 1.jpg, 2.jpg, and 3.jpg; the random script would correspondingly load a random picture.

So you would want to rename the pictures: 1.jpg or 4.jpg.. when the PHP picks for example "4", 4.jpg would load.
__________________
-=-
Zune > iPod
Currently Playing: HL2 + GRiD + WiC
Ultimate Wallpaper Site Antec 900 Cable/sound Mod
Obama? Gag me with a fork.

System: AM2saucee
CPU
|AM2 Athlon 4400+|
Motherboard
|DFI Lan Party DK 790FX-M2RS|
Memory
|4GB G.Skill | 2GB PNY DDR2 800|
Graphics Card
|GeCube 3870 512MB 850/1250|
Hard Drive
|250GB Maxtor sATA|
Sound Card
|Creative Audigy 2 ZS|
Power Supply
|Silverstone Strider 600W|54amps|
Case
|Antec 900|
CPU cooling
|Arctic Cooling|Arctic Freezer 64|
GPU cooling
|Zalman VF700|
OS
|x64 Vista Ultimate|
Monitor
|Acer 20" x203w|1680x1050|
Higgins is online now   Reply With Quote
Old 04-10-08   #6 (permalink)
4 gigs of hert
 
Kopi's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Hamilton Ontario
Posts: 7,270

Rep: 459 Kopi is a proven memberKopi is a proven memberKopi is a proven memberKopi is a proven memberKopi is a proven member
Unique Rep: 303
Trader Rating: 17
Default

Oh okay, I'm with ya.

1.jpg
2.jpg
3.jpg

They are all different sizes, and I'd like to alternate between them. Would the code be
Code:
<img src="http://site/images/<?php echo(rand(1,3)); ?>.jpg"/>
Or do i have to change some stuff
__________________
Quote:
Originally Posted by FlaKing View Post
I noticed it when everybody started to use it to describe "300". Afterwards, everything became "epic". Epic fail, shoes, mouse, laptop, mom, El Camino, Sebring, paper towel, etc.

System: Kopisaurus
CPU
Intel e8400 Q810A198 @4ghz 1.368v
Motherboard
ASUS P5K Premium Black Pearl
Memory
2x2gb Mushkin Ascent 1066mhz
Graphics Card
XFX 8800gt Alpha Dog 512mb w/ TT DuOrb
Hard Drive
160gb WD / 250gb Barracuda
Sound Card
Creative SoundBlaster Audigy SE 7.1
Power Supply
OCz GameXstream 700w
Case
NZXT Trinity
CPU cooling
Noctu NH-U12P w/YL D12SH 88cfm
GPU cooling
Thermaltake DuOrb
OS
Windows Vista Ultimate 64bit
Monitor
LG Flatron 22" ws 3000:1 - 2ms
Kopi is offline Overclocked Account   Reply With Quote
Old 04-10-08   #7 (permalink)
Audiophile
 
Higgins's Avatar
 
amd ati

Join Date: Dec 2005
Location: The Burbs of Detroit City
Posts: 3,199

Rep: 227 Higgins is acknowledged by manyHiggins is acknowledged by manyHiggins is acknowledged by many
Unique Rep: 184
Hardware Reviews: 4
Trader Rating: 2
Default

I would say yes, but i dont do HTML.. i was just making sure you understood what he was saying

Can you test it?

Good Luck
~Higgins
__________________
-=-
Zune > iPod
Currently Playing: HL2 + GRiD + WiC
Ultimate Wallpaper Site Antec 900 Cable/sound Mod
Obama? Gag me with a fork.

System: AM2saucee
CPU
|AM2 Athlon 4400+|
Motherboard
|DFI Lan Party DK 790FX-M2RS|
Memory
|4GB G.Skill | 2GB PNY DDR2 800|
Graphics Card
|GeCube 3870 512MB 850/1250|
Hard Drive
|250GB Maxtor sATA|
Sound Card
|Creative Audigy 2 ZS|
Power Supply
|Silverstone Strider 600W|54amps|
Case
|Antec 900|
CPU cooling
|Arctic Cooling|Arctic Freezer 64|
GPU cooling
|Zalman VF700|
OS
|x64 Vista Ultimate|
Monitor
|Acer 20" x203w|1680x1050|
Higgins is online now   Reply With Quote
Old 04-10-08   #8 (permalink)
iRun
 
Chipp's Avatar
 
intel ati

Join Date: Dec 2004
Posts: 13,440
Blog Entries: 28

FAQs Submitted: 18
Folding Team Rank: 179
Team Name: Rough Riders
Hardware Reviews: 3
Trader Rating: 8
Default

Well, you might get some better results by changing the path to the image files to wherever your keeping your images, etc.

I threw up a simple test page for you - I think you can see the directory structure and how the PHP actually works when you look at the source code in your browser (as the browser will display just the HTML after the number has been put into the filename).

http://sethhochberg.com/random/index.php

The exact code I used for that page is this:
PHP Code:
<img src="http://sethhochberg.com/random/images/<?php echo(rand(1,3)); ?>.jpg" alt="kopi test" />

System: Linux exclusive? I think so.
CPU
Intel E2160 @ 3.1ghz (Summer OC)
Motherboard
Abit IP35-E
Memory
2x1gb OCZ Plat Rev. 2 DDR2
Graphics Card
ATI X1900XT
Hard Drive
120gb Hitatchi Deskstar IDE
Sound Card
Onboard -> AVR210 as DAC (X-Fi + linux = bad)
Power Supply
CoolerMaster RM-500
Case
CoolerMaster Centruion 5
CPU cooling
Ultra90 (lapped) and Sanyo Denki 92mm
GPU cooling
Zalman VF900
OS
ArchLinux x64
Monitor
Viewsonic VE175b
Chipp is offline I fold for Overclock.net Overclocked Account Chipp's Gallery   Reply With Quote
Old 04-10-08   #9 (permalink)
4 gigs of hert
 
Kopi's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Hamilton Ontario
Posts: 7,270

Rep: 459 Kopi is a proven memberKopi is a proven memberKopi is a proven memberKopi is a proven memberKopi is a proven member
Unique Rep: 303
Trader Rating: 17
Default

Chipp, you're my hero.

I understand now, thanks alot to the both of you and thanks for throwing that test up for me Chipp!

__________________
Quote:
Originally Posted by FlaKing View Post
I noticed it when everybody started to use it to describe "300". Afterwards, everything became "epic". Epic fail, shoes, mouse, laptop, mom, El Camino, Sebring, paper towel, etc.

System: Kopisaurus
CPU
Intel e8400 Q810A198 @4ghz 1.368v
Motherboard
ASUS P5K Premium Black Pearl
Memory
2x2gb Mushkin Ascent 1066mhz
Graphics Card
XFX 8800gt Alpha Dog 512mb w/ TT DuOrb
Hard Drive
160gb WD / 250gb Barracuda
Sound Card
Creative SoundBlaster Audigy SE 7.1
Power Supply
OCz GameXstream 700w
Case
NZXT Trinity
CPU cooling
Noctu NH-U12P w/YL D12SH 88cfm
GPU cooling
Thermaltake DuOrb
OS
Windows Vista Ultimate 64bit
Monitor
LG Flatron 22" ws 3000:1 - 2ms
Kopi is offline Overclocked Account   Reply With Quote
Old 04-11-08   #10 (permalink)
iRun
 
Chipp's Avatar
 
intel ati

Join Date: Dec 2004
Posts: 13,440
Blog Entries: 28

FAQs Submitted: 18
Folding Team Rank: 179
Team Name: Rough Riders
Hardware Reviews: 3
Trader Rating: 8
Default

Not a problem at all.

Good luck with your site, keep on codin'!

System: Linux exclusive? I think so.
CPU
Intel E2160 @ 3.1ghz (Summer OC)
Motherboard
Abit IP35-E
Memory
2x1gb OCZ Plat Rev. 2 DDR2
Graphics Card
ATI X1900XT
Hard Drive
120gb Hitatchi Deskstar IDE
Sound Card
Onboard -> AVR210 as DAC (X-Fi + linux = bad)
Power Supply
CoolerMaster RM-500
Case
CoolerMaster Centruion 5
CPU cooling
Ultra90 (lapped) and Sanyo Denki 92mm
GPU cooling
Zalman VF900
OS
ArchLinux x64
Monitor
Viewsonic VE175b
Chipp is offline I fold for Overclock.net Overclocked Account Chipp's Gallery   Reply With Quote
Reply



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



All times are GMT -4. The time now is 01:22 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.20117 seconds with 9 queries