Php > Databases
This banner rotator is a little bit different from others, the banner will change
This banner rotator is a little bit different from others, the banner will change only ones a day. I used the php function rand() because I think that MySQL's "ORDER BY RAND()" and the php function array_rand() are only a second choice. 0) { $id_today = mysql_result($check_today_res, 0, "todays_id"); } else { // if not select a random id and store the id in the table with current date $get_ids_sql = "SELECT id FROM banners WHERE status = 'on'"; $get_ids_res = mysql_query($get_ids_sql); $get_ids_array = array(); while ($get_ids = mysql_fetch_object($get_ids_res)) { $get_ids_array[] = $get_ids->id; } $num = count($get_ids_array); // I use the function rand() because other random functions are not "really random" $rand_num = rand(0, $num-1); $id_today = $get_ids_array[$rand_num]; mysql_query("INSERT INTO rand_banner (id, date, todays_id) VALUES (NULL, NOW(), $id_today)"); } // at least select the record with the todays ID $result = mysql_query("SELECT link AS url, alt_title, image FROM banners WHERE id = $id_today"); $obj = mysql_fetch_object($result); // this example will show the current banner echo "
url."\">
image."\" alt=\"".$obj->alt_title."\" border=\"0\">
"; ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage