Free web development scripts for the webmasterDevelopment Scripts


 social media marketing services
 Site Navigation
Clicky Web Analytics
 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 1 user 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 Paper Free Invoicing
 o Tutorials
 o Expired Domain Crawler
 o PFB UK
 o PFB
 o OxyScripts

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


Recent Additions (from all categories)

(PHP) T Shirt Printing Software

(PHP) Youtube Video Organizer Script

(PHP) MP3z - MP3 Search Engine Script

(PHP) Recipez- PHP Recipe Script

(ASP) Stop image hotlinking and downloading. Web image protection is easy with Image Trapper.

Top Rated Scripts

(Javascripts) Javascript Delayed Redirection Rating: 5

(PHP) Random Links and images with PHP & MySQL Rating: 5

(PHP) RSS/XML news feed headline grabber! Rating: 5

(PHP) Random Signatures/Avatars Rating: 5

(Javascripts) Detecting Client Web Browser Rating: 5

© Copyright 2003 - Devscripts.net  Web Analytics