PDA

View Full Version : images displaying at certain times (holidays etc...)


kona72
02-16-2007, 12:00 AM
Hey all,

I think I might be on the right track here...
I am trying to have certain pictures display at different times all controlled by the DB. My thoughts are this...

1. create the table with 3 fields such as this...


-- phpMyAdmin SQL Dump-- version 2.9.0.3-- http://www.phpmyadmin.net-- -- Host: localhost-- Generation Time: Feb 15, 2007 at 06:46 PM-- Server version: 5.0.27-- PHP Version: 5.2.0-- -- Database: `areyourank`-- -- ---------------------------------------------------------- -- Table structure for table `pics`-- CREATE TABLE `pics` ( `rec_id` int(11) NOT NULL auto_increment, `time` time NOT NULL, `name` varchar(50) NOT NULL, PRIMARY KEY (`rec_id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;-- -- Dumping data for table `pics`-- INSERT INTO `pics` (`rec_id`, `time`, `name`) VALUES (1, '18:00:00', 'ex_1.jpg'),(2, '19:00:00', 'ex_2.jpg'),(3, '20:00:00', 'ex_3.jpg');


Then i create the page with query. The query will check the 'time' column and compare it to the server time and depending on the DB entry the operator will be '>=' compared to server variable ()time or date... depending on how often i want it to change.

Here is a BASIC page... (i know DavidJ.... it's the DW code but i am just playing... I will clean it up once i figure this out HONEST!!!)


<?php require_once('Connections/rank.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$colname_rsTime = "-1";
if (isset($_SERVER['()time'])) {
$colname_rsTime = (get_magic_quotes_gpc()) ? $_SERVER['()time'] : addslashes($_SERVER['()time']);
}
mysql_select_db($database_rank, $rank);
$query_rsTime = sprintf("SELECT * FROM pics WHERE `time` >= %s", GetSQLValueString($colname_rsTime, "date"));
$rsTime = mysql_query($query_rsTime, $rank) or die(mysql_error());
$row_rsTime = mysql_fetch_assoc($rsTime);
$totalRows_rsTime = mysql_num_rows($rsTime);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<img src="/images/<?php echo $row_rsTime['name']; ?>" />
</body>
</html>
<?php
mysql_free_result($rsTime);
?>


Am I on the right path at least?? I think I am...

THANKS!!!!

kona72
02-16-2007, 12:53 AM
Well... Upon further investigation i have found with this bit o' code...



$url = '****';
echo '<img src="' . $url . strtolower(date('M')) . '.jpg">' . "\n";



I kinda think I am WAY Over killing this by using the DB....

Hmmm..(thinking out loud.....)

davidj
02-16-2007, 05:47 AM
yes you have got it

although you better change that code...

Dont tidy it up... just bloody rewrite it

i am very disapointed in you kona for allowing DW to write this.

kona72
02-16-2007, 02:50 PM
**hangs head in shame**

Sorry DavidJ

I'll post the new code as soon as i re-write it....

davidj
02-16-2007, 03:04 PM
looking at this line...


$url = '****';
echo '<img src="' . $url . strtolower(date('M')) . '.jpg">' . "\n";


this will render as...


<img src="****february.jpg" >

is this what you want?

also i would assign this to a var and echo the var where you want it dispayed