where could i find a code for a script that randomly produeces a script for an image and a link for that image?
need a script.
>> produces a script for an image?
what do you mean?
Do you want to show an image by random?
For that I got a script.
If you want to show a banner with a link to a sponsor, you'll need a database.
what do you mean?
Do you want to show an image by random?
For that I got a script.
If you want to show a banner with a link to a sponsor, you'll need a database.
Something like this?
Note that this is really the most basic thing you can do.
EDIT: Typo
Note that this is really the most basic thing you can do.
| Code: |
|
<?php $images = array('pic1.jpg','pic2.jpg','pic3.jpg'); srand(time()); $random = (rand(0,count($images)-1)); echo '<img src="' . $images[$random] . '" /><br /><a href="' . $images[$random] . '">' . $images[$random] . '</a>'; ?> |
EDIT: Typo
| TomS wrote: |
| If you want to show a banner with a link to a sponsor, you'll need a database. |
I have the ability to create a database so how on earth would i do it?
You need just one table in your database. (I call it table, so you know what is meant. Replace it every time you see it with your name of the table e.g. banners)
This contents of three columns.
1. "id"
2. "image"
3. "link"
Configure this with phpMyAdmin.
----------------------------------------
First of all we have to connect to our database.
Then we select our table to get its content:
Now we select a random row (just edit x to number of your bannerlinks)
Then we have to close our connection:
Now the php-variable "$image" contents the imagepath and "$link" the url to the site.
This code shows the image linking to the website:
For showing a new image each X seconds use:
You should use a frame or an inlineframe to view the banner. Otherwise the whole page will be refreshed.
This contents of three columns.
1. "id"
2. "image"
3. "link"
Configure this with phpMyAdmin.
----------------------------------------
First of all we have to connect to our database.
| Code: |
| <?
$connection=mysql_connect("yourdomain.com", "sql_username","sql_userpassword"); |
Then we select our table to get its content:
| Code: |
| mysql_select_db("table");
|
Now we select a random row (just edit x to number of your bannerlinks)
| Code: |
| $image = "SELECT image FROM table WHERE id == rand(1,x)"; #Action
$imageresult = mysql_query($image); #Execute SQL-Commands $link = "SELECT link FROM table WHERE id == rand(1,x)"; #Action $linkresult = mysql_query($link); #Execute SQL-Commands |
Then we have to close our connection:
| Code: |
| mysql_close($connection);
?> |
Now the php-variable "$image" contents the imagepath and "$link" the url to the site.
This code shows the image linking to the website:
| Code: |
| <a href=<? echo $link; ?><img src=<? echo $image; ? border=0></a>
|
For showing a new image each X seconds use:
| Code: |
|
<html><head> <meta http-equiv="refresh" content="X"> </head> |
You should use a frame or an inlineframe to view the banner. Otherwise the whole page will be refreshed.
