Below is a code I want to use, it's going to query a MySQL DB and pull a random image and link to that image to be displayed. Below is the code...
Code: Select all
// 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 Results to Web Page
echo "<a href=\"" . $row["link"] . "\">
<img src=\"" . $row["image"] . "\" border=0 alt=\"" . $row["text"] . "\">
</a>" ;
}
?>
Code: Select all
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;
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");
Also, is there any way I can make this process faster and less intensive on the web server, this script will most likely be called by web visitors at the same time, with about 100 to 200 visitors at one time. Any help is greatly apperciated.