Hi
I am building a site that will be powered by a Mysql database.
Everything has been going great until I hit this problem.
Because the site will contain TV Listings data, I have requirement for the user to select a date from a row of 7 in order to get results from the database.
To make navigation easier I want the date the user selected to be highlighted.
By adapting a tutorial I found online I was able to get this to work by adding a "navigation" div and some CSS into my stylesheet as shown below.
So currently I am able to select a date from the row of 7 and it will be highlighted just as I wanted but there is problem.
The 2 vital lines in my PHP are in the head <?php $thisPage=$_GET['date']; ?> and in the navigation div <li<?php if ($thisPage=='12-07')
echo " id=\"currentpage\""; ?>>
Currently I have had to manual insert this value '12-07' to equal the value of the
$_GET['date'];
I want the value '12-07' to be a variable obtained from the $Date variable.
Otherwise I will to constantly edit my PHP for the current "dates"
Please note that most of this PHP was created by Dreamweaver CS4 and not handwritten by myself.
I have limited knowledge of PHP hence why I am having problems solving this.
I will greatly appreciate your assistance.
PHP & HTML
<?php require_once('Connections/schedule.php'); ?>
<?php require_once('Connections/main.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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;
}
}
mysql_select_db($database_schedule, $schedule);
$query_Day1 = "SELECT * FROM schedule WHERE id = -1";
$Day1 = mysql_query($query_Day1, $schedule) or die(mysql_error());
$row_Day1 = mysql_fetch_assoc($Day1);
$totalRows_Day1 = mysql_num_rows($Day1);
mysql_select_db($database_schedule, $schedule);
$query_Day2 = "SELECT * FROM schedule WHERE id = -2";
$Day2 = mysql_query($query_Day2, $schedule) or die(mysql_error());
$row_Day2 = mysql_fetch_assoc($Day2);
$totalRows_Day2 = mysql_num_rows($Day2);
mysql_select_db($database_schedule, $schedule);
$query_Day3 = "SELECT * FROM schedule WHERE id = -3";
$Day3 = mysql_query($query_Day3, $schedule) or die(mysql_error());
$row_Day3 = mysql_fetch_assoc($Day3);
$totalRows_Day3 = mysql_num_rows($Day3);
mysql_select_db($database_schedule, $schedule);
$query_Day4 = "SELECT * FROM schedule WHERE id = - 4";
$Day4 = mysql_query($query_Day4, $schedule) or die(mysql_error());
$row_Day4 = mysql_fetch_assoc($Day4);
$totalRows_Day4 = mysql_num_rows($Day4);
mysql_select_db($database_schedule, $schedule);
$query_Day5 = "SELECT * FROM schedule WHERE id = -5";
$Day5 = mysql_query($query_Day5, $schedule) or die(mysql_error());
$row_Day5 = mysql_fetch_assoc($Day5);
$totalRows_Day5 = mysql_num_rows($Day5);
mysql_select_db($database_schedule, $schedule);
$query_Day6 = "SELECT * FROM schedule WHERE id = -6";
$Day6 = mysql_query($query_Day6, $schedule) or die(mysql_error());
$row_Day6 = mysql_fetch_assoc($Day6);
$totalRows_Day6 = mysql_num_rows($Day6);
mysql_select_db($database_schedule, $schedule);
$query_Day7 = "SELECT * FROM schedule WHERE id = -7";
$Day7 = mysql_query($query_Day7, $schedule) or die(mysql_error());
$row_Day7 = mysql_fetch_assoc($Day7);
$totalRows_Day7 = mysql_num_rows($Day7);
$coldate_schedule = date('d-m', strtotime('yesterday'));
if (isset($_GET['date'])) {
$coldate_schedule = $_GET['date'];
}
mysql_select_db($database_main, $main);
$query_schedule = sprintf("SELECT * FROM main WHERE channel = 'One' AND date = %s AND time IN (19, 20, 21, 22, 23, 00, 01, 02, 03, 04, 05)", GetSQLValueString($coldate_schedule, "int"));
$schedule = mysql_query($query_schedule, $main) or die(mysql_error());
$row_schedule = mysql_fetch_assoc($schedule);
$totalRows_schedule = mysql_num_rows($schedule);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB" lang="en-GB"><head profile="http://dublincore.org/documents/dcq-html/">
<link rel="stylesheet" type="text/css" href="http://localhost//files/stylesheet.css" />
<?php $thisPage=$_GET['date']; ?>
</a></li>
</ul>
</a><br /> <div id="navigation">
<ul>
<li<?php if ($thisPage=='12-07')
echo " id=\"currentpage\""; ?>>
<a href="<?php echo $row_Day1['date']; ?> "><?php echo $row_Day1['day']; ?></a></li>
<li<?php if ($thisPage=="11-07")
echo " id=\"currentpage\""; ?>>
<a href="<?php echo $row_Day2['date']; ?>"><?php echo $row_Day2['day']; ?></a></li>
<li<?php if ($thisPage=="10-07")
echo " id=\"currentpage\""; ?>>
<a href="<?php echo $row_Day3['date']; ?>"><?php echo $row_Day3['day']; ?></a></li>
<li<?php if ($thisPage=="09-07")
echo " id=\"currentpage\""; ?>>
<a href="<?php echo $row_Day4['date']; ?>"><?php echo $row_Day4['day']; ?></a></li>
<li<?php if ($thisPage=="08-07")
echo " id=\"currentpage\""; ?>>
<a href="<?php echo $row_Day5['date']; ?>"><?php echo $row_Day5['day']; ?></a></li>
<li<?php if ($thisPage=="07-07")
echo " id=\"currentpage\""; ?>>
<a href="<?php echo $row_Day6['date']; ?>"><?php echo $row_Day6['day']; ?></a></li>
<li<?php if ($thisPage=="06-07")
echo " id=\"currentpage\""; ?>>
<a href="<?php echo $row_Day7['date']; ?>"><?php echo $row_Day7['day']; ?></a></li>
</ul>
</body></html>
<?php
mysql_free_result($Day1);
mysql_free_result($Day2);
mysql_free_result($Day3);
mysql_free_result($Day4);
mysql_free_result($Day5);
mysql_free_result($Day6);
mysql_free_result($Day7);
mysql_free_result($schedule);
?>
CSS
#navigation ul {
list-style: none;
margin: 0;
padding: 0;
}
#navigation li {
background: #ccc;
border-left: 1px solid #999;
float: left;
margin: 0;
padding: 0;
}
#navigation a {
color: #666;
font-weight: bold;
padding: 5px 10px;
text-decoration: none;
}
#navigation a:hover {
color: #333;
}
#navigation #currentpage a {
background: #fff;
color: #333;
}