Free web development scripts for the webmasterDevelopment Scripts

 Site Navigation
 o Development Scripts
 o Text Only Edition
 o PHP.net News
 o Tutorials
 o Register an account
 o New entries this week
 o Affiliates/Links
 o Contact Us
 o About us
 o Advanced Search

 Browse Path
 o 6 users online
 o Most users online: 67
 o Home
  o PHP
   o Random
    o Script

 Member Login
User Name
Password

 Standards
Valid XHTML 1.0!
Valid 
CSS!

 Recommended Links
 o PHP Freaks
 o Designer Baby Clothes
 o Advertise Here Make Money
 o OxyScripts
 o Free Wedding Websites
 o Wedding Vendor Directory
 o designplace
 o devnet
 o Open Source Design

Random Links and images with PHP & MySQL (Rated 5)

Description:

This script allows any number of images to be referenced and have an associated hyperlink attached, which makes it great for 88x31 buttons which are commonplace throughout the web. The script requires a web server with PHP and a MySQL database to store the data.

Code starts here


Creating the database table.


// Code to create the table.

CREATE TABLE `links` (

`id` int(11) NOT NULL auto_increment,
`link` text NOT NULL,
`image` longtext NOT NULL,
`text` text NOT NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM;

Inserting the data with an SQL statement

// SQL statement to insert values into the database. (Add more if required)

insert into links values ('NULL',"http://www.site1.com", "path/image.gif", "website description");
insert into links values ('NULL',"http://www.site2.com", "path/image.gif", "website description");
insert into links values ('NULL',"http://www.site3.com", "path/image.gif", "website description");


The PHP Script

// PHP script
<?
// Connect to the database
mysql_connect ('localhost', 'username', 'password') ;
mysql_select_db ('database_name_here');

// Edit this number to however many links you want displaying
$num_displayed = 3 ;

// Select random rows from the database
$result = mysql_query ("SELECT * FROM links ORDER BY RAND() LIMIT $num_displayed");

// For all the rows that you selected
while ($row = mysql_fetch_array($result))

{
// Display them to the screen...

echo "<a href=\"" . $row["link"] . "\">
<img src=\""
. $row["image"] . "\" border=0 alt=\"" . $row["text"] . "\">
</a>"
;
}
?>


Submitted by Devscripts on 13-02-2003 20:18


Rate This Script

User Contributed Comments

On 27-10-2004 9:47 russ said:

Is there anyway to make a form which users can submit their own data to the affiliates type program?


Registered Members login
© Copyright 2003 - Devscripts.net