FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


need a script.





mistuh griddlez
where could i find a code for a script that randomly produeces a script for an image and a link for that image?
TomS
>> 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.
smartbei
Something like this?
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
mistuh griddlez
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?
TomS
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.


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.
Related topics
Which is your favourite weblog Script?
Chat script
Script Upload (obiefileman)
script backup database
Script run background
Can someone make me a php script?
target = _parent redirect script?
Bookmark Script:
Some Script Show
Image transparency script
A script for Loading
Set As Home Page Script (IE Only)
Where I can find a 3d chat script
Un script installer? laissez faire frihost!
Need a script - navigation
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.