Jump to content
OtakuBoards

Recommended Posts

Posted
I've been using this code to show all of my websites banners but it only shows 4 of them. Can someone figure out what's wrong? I'm not very good with Java.


[php][/php]
Posted
Are you just trying to display one of these randomly whenever it loads up?

If your server can use PHP (I know some free ones can't), there are far better ways to go about this.
Posted
Yes, I'm trying to get random banners. I'm not sure if geocities supports php. I will be switching to a paid service soon(most likely Surpass Hosting), so could you explain how to do this in php for the future?
Posted
If you just want random banners, that's something rather easy to accomplish.

[CODE]
var pos=Math.floor(Math.random()*(A-1))
var B=new Array(A)
B[0] = "C"
B[1] = "D"
.
.
.
B[A-1] = "E"

function getbanner(){
document.write(< IMG SRC=" +B[pos]+">")
}
[/CODE]

A = number of different banners you have.
B = name of the array of banners.
C...E = the URLs for your banners.

Basically this code just picks a random number and creates an array of URLs. When you call the function getbanner() it just writes the code for an image based on the random number it picked earlier.

Remember you have to call the function somewhere in your code. This particular script should go somewhere up towards the top. Then when you want your banner inserted, write something like [CODE]getbanner()[/CODE] and you're done.

And also note all the code needs to be wrapped with < script > and < /script > tags.
Posted
I use Surpass. Very recommended on my part.

If you use PHP in the future, here is the code:

[PHP]
//Edit this line to the url of your image folder to randomize
//Must be a relative URL in your server, do not put in a forward
//or trailing slash for it to work.
$url='images/banners';
//Stop editing, that is all. Call the image with That's all, enjoy. :D

$files=array();
if ($handle=opendir("$url")) {
while(false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(substr($file,-3)=='gif' || substr($file,-3)=='jpg' || substr($file,-3)=='png' || substr($file,-3)=='bmp') $files[count($files)] = $file;
}
}
}
closedir($handle);

$random=rand(0,count($files)-1);
if(substr($files[$random],-3)=='gif') header("Content-type: image/gif");
elseif(substr($files[$random],-3)=='jpg') header("Content-type: image/jpeg");
elseif(substr($files[$random],-3)=='png') header("Content-type: image/png");
elseif(substr($files[$random],-3)=='bmp') header("Content-type: image/bmp");
readfile("$url/$files[$random]");

?>[/PHP]

I don't remember where I got it. The problem with most pre-made scripts you'll find online that do this is that they require you to put in the name of every single last image in there. It's time consuming and obviously increases the file size needlessly.

With this one, you just specify the folder and that's the end of it. Just take this code, edit it and put it in "randomimage.php" or whatever you want. Then when you want to use it, just use that php file as the image source.
Posted
[quote name='Morpheus']Can I just C&P the first code and fill in the blanks?[/quote]

Yeah, should be OK as long as everything is filled in right. Oh and be sure to delete the space between the arrow and IMG.
Posted
What did I do wrong?

[PHP]








[/PHP]
Posted
I've got it working now.

[PHP]

[/PHP]

And then, somewhere in the body of your document, just put:

[PHP]

[/PHP]

I tested this and it worked. Part of the problem was that you had a space in a variable name (Weekly Links I changed to WeeklyLinks), and part of it was my fault.
Posted
Like so:

[PHP]

[/PHP]

That'll show an annoying border on the banners though. Edit the getbanner() function like so:

[PHP]
function getbanner(){
document.write('')
}
[/PHP]

...and you'll have a banner that links without a border.
Posted
[color=blue]You're going to want to include the link tag [url="http://www.otakuboards.com/..."][/url]in the document.write part of the function though. Otherwise, you won't be able to include different sites ads and they will always link to the same place.[/color]
Posted
[quote name='Petie][color=blue]You're going to want to include the link tag [url="http://www.otakuboards.com/..."][/url']in the document.write part of the function though. Otherwise, you won't be able to include different sites ads and they will always link to the same place.[/color][/quote]


That's true. However I believe in this case they're all linking to the same place (all the banners are for the same site).

But if they do need to go to different places, I could help there too.
Posted
[quote name='Morpheus']Where does the url go in the borderless code?[/quote]

You just put links around the script tags.

[PHP]

[/PHP]

The image will be borderless because of the re-written getbanner() function. The link is still the same old tag.
Posted
What's wrong?
[PHP]





[/PHP]

It's all OK until the "getbanner()" function. While it will work, you'll get a border. So REPLACE the getbanner() function above with this one:

[PHP]
function getbanner(){
document.write('')
}
[/PHP]

And that part is good.

However, this second part is wrong:

[PHP]

document.write('')
}
[/PHP]

Here's all you need to put:

[PHP]

[/PHP]

And you'll have a borderless banner that links somewhere on your site. Remember, this second part can go anywhere in your page. It doesn't have to follow the first part of the script at all.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...