Copy link to clipboard
Copied
Hi all,
I have a Recordset created in Dreamweaver that lists all jobs that our team have to complete... I currently have a list menu (drop-down) called 'OfficerSelect' which includes the following values:
Andy
Dave
Matt
Tom
All
I have used the SQL below (see attached screen shot) to get the list menu to filter through the jobs for the staff name selected, however I would like it to list all jobs for all staff when the value 'All' is selected.
Does anyone have any ideas how this can be done?
Thanks,
Tom
Copy link to clipboard
Copied
You will need to modify the code and evaluate the value of the dropdown item - then create a different WHERE clause if 'ALL' was selected. DW won't do this for you - you'll need to hand code this.
Copy link to clipboard
Copied
Hi...
I agree, this is where I got stuck. I dont know enough about php/sql etc to do this.. here is what I have tried but it didn't work...
SELECT *
FROM tms
WHERE
(if colname = 'All' then *
else responsible_officer = colname)
AND task_type = 'O-Track Set Up'
AND signed_off = 'N'
Could you help me write this code please?
Cheers,
Tom
Copy link to clipboard
Copied
You're trying evaluate the value within the SQL, which won't work. You need to adapt your scripting code for this. Please attach the script for this page.
Copy link to clipboard
Copied
Hi,
I have pasted the entire script below. I hope this helps (it looks horrendous to me, I can only do things through the wizards and WYSIWYG features!)...
Thanks so much for looking at this.
Tom
------
<?php require_once('../Connections/Optimum.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "login.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?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;
}
}
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;
}
}
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;
}
}
$currentPage = $_SERVER["PHP_SELF"];
mysql_select_db($database_Optimum, $Optimum);
$query_CompanyDetails = "SELECT * FROM website_contacts";
$CompanyDetails = mysql_query($query_CompanyDetails, $Optimum) or die(mysql_error());
$row_CompanyDetails = mysql_fetch_assoc($CompanyDetails);
$totalRows_CompanyDetails = mysql_num_rows($CompanyDetails);
$maxRows_TMS_OutstandingOtrackSetUp = 10;
$pageNum_TMS_OutstandingOtrackSetUp = 0;
if (isset($_GET['pageNum_TMS_OutstandingOtrackSetUp'])) {
$pageNum_TMS_OutstandingOtrackSetUp = $_GET['pageNum_TMS_OutstandingOtrackSetUp'];
}
$startRow_TMS_OutstandingOtrackSetUp = $pageNum_TMS_OutstandingOtrackSetUp * $maxRows_TMS_OutstandingOtrackSetUp;
$colname_TMS_OutstandingOtrackSetUp = "-1";
if (isset($_POST['OfficerSelect'])) {
$colname_TMS_OutstandingOtrackSetUp = $_POST['OfficerSelect'];
}
mysql_select_db($database_Optimum, $Optimum);
$query_TMS_OutstandingOtrackSetUp = sprintf("SELECT * FROM tms WHERE responsible_officer = %s AND task_type = 'O-Track Set Up' AND signed_off = 'N'", GetSQLValueString($colname_TMS_OutstandingOtrackSetUp, "text"));
$query_limit_TMS_OutstandingOtrackSetUp = sprintf("%s LIMIT %d, %d", $query_TMS_OutstandingOtrackSetUp, $startRow_TMS_OutstandingOtrackSetUp, $maxRows_TMS_OutstandingOtrackSetUp);
$TMS_OutstandingOtrackSetUp = mysql_query($query_limit_TMS_OutstandingOtrackSetUp, $Optimum) or die(mysql_error());
$row_TMS_OutstandingOtrackSetUp = mysql_fetch_assoc($TMS_OutstandingOtrackSetUp);
if (isset($_GET['totalRows_TMS_OutstandingOtrackSetUp'])) {
$totalRows_TMS_OutstandingOtrackSetUp = $_GET['totalRows_TMS_OutstandingOtrackSetUp'];
} else {
$all_TMS_OutstandingOtrackSetUp = mysql_query($query_TMS_OutstandingOtrackSetUp);
$totalRows_TMS_OutstandingOtrackSetUp = mysql_num_rows($all_TMS_OutstandingOtrackSetUp);
}
$totalPages_TMS_OutstandingOtrackSetUp = ceil($totalRows_TMS_OutstandingOtrackSetUp/$maxRows_TMS_OutstandingOtrackSetUp)-1;
$colname_TMS_OustandingDataSEF = "-1";
if (isset($_POST['OfficerSelect'])) {
$colname_TMS_OustandingDataSEF = $_POST['OfficerSelect'];
}
mysql_select_db($database_Optimum, $Optimum);
$query_TMS_OustandingDataSEF = sprintf("SELECT * FROM tms WHERE responsible_officer = %s AND task_type = 'dataSEF Analysis' AND signed_off = 'N'", GetSQLValueString($colname_TMS_OustandingDataSEF, "text"));
$TMS_OustandingDataSEF = mysql_query($query_TMS_OustandingDataSEF, $Optimum) or die(mysql_error());
$row_TMS_OustandingDataSEF = mysql_fetch_assoc($TMS_OustandingDataSEF);
$totalRows_TMS_OustandingDataSEF = mysql_num_rows($TMS_OustandingDataSEF);
$queryString_TMS_OutstandingOtrackSetUp = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_TMS_OutstandingOtrackSetUp") == false &&
stristr($param, "totalRows_TMS_OutstandingOtrackSetUp") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_TMS_OutstandingOtrackSetUp = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_TMS_OutstandingOtrackSetUp = sprintf("&totalRows_TMS_OutstandingOtrackSetUp=%d%s", $totalRows_TMS_OutstandingOtrackSetUp, $queryString_TMS_OutstandingOtrackSetUp);
require_once '../scripts/Mobile_Detect.php';
$detect = new Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
$scriptVersion = $detect->getScriptVersion();
?><!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=utf-8" />
<title>Optimum O-Track : Online Pupil Tracking Systems and Software for EYFS, KS1 and KS2</title>
<link rel="stylesheet" type="text/css" href="/style/fonts/fonts.css" />
<link rel="stylesheet" type="text/css" href="../style/style.css" />
<style type="text/css">
<!--
.style1 {font-size: 14px}
-->
</style>
</head>
<?php
if ($detect->isMobile() || $detect->isTablet() ) {
echo "<body style='width:1000px;'>";
}
else
{
echo "<body>";
}
?>
<div id="header">
<div class="header_in">
<div class="logo">
<a href="../index.php"><img src="../images/logo.jpg" width="146" height="127" alt="optimum logo" border="0" /></a> </div>
<div class="right">
<div class="right_top">
Need some help? Call <span style="color:#215fa4"><?php echo $row_CompanyDetails['Telephone']; ?></span> <span style="color:#666666">or</span> <a href="../contactus.php">contact us</a> </div>
<div class="menu">
<ul>
<li><a href="../index.php">Home</a></li>
<li><a href="../products.php">Products</a></li>
<li><a href="../support.php">Support</a></li>
<li ><a href="../customer.php" >Customer</a></li>
<li><a href="../contactus.php">Contact us</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="mid_section">
<?php
if ($detect->isMobile() || $detect->isTablet() ) {
}
else
{
echo "<div class='social_right'>
<br />
Find <br />
us on
<a href='http://www.facebook.com/OptimumReports' target='_blank'><img src='images/facebook.jpg' alt='facebook' width='30' height='30' /></a>
<a href='https://twitter.com/OptimumReports' target='_blank'><img src='images/twiiter.jpg' alt='twitter' width='30' height='30' /></a>
<br /><br />
</div>";
}
?>
<div class="content">
<div class="navigation">
<div class="text">
<span style="color:#000;"><a href="home.php">TMS Home</a> / <a href="<?php echo $logoutAction ?>">Log out</a></span></div>
</div>
<div class="content_hold">
<div class="content_left_top">
</div>
<div class="content_left">
<div class="text">
<h1 class="fontface">TMS</h1>
<p>Welcome to the Optimum Task Management System (TMS).
Below is a list of all outstanding tasks. To view an archive of all 'signed off' tasks click <a href="archive.php">here</a>.</p>
<form id="form1" name="form1" method="post" action="">
<h3 align="center">Filter by Responsible Officer</h3>
<p align="center">
<select name="OfficerSelect" id="OfficerSelect">
<option value="All">All</option>
<option value="Andrew">Andrew</option>
<option value="Andy">Andy</option>
<option value="Dave">Dave</option>
<option value="Mary">Mary</option>
<option value="Matt">Matt</option>
<option value="Tommy">Tommy</option>
<option value="Tom">Tom</option>
<option value="select" selected="selected">select</option>
</select>
<input type="submit" name="button" id="button" value="Submit" />
</p>
</form>
<h2>Outstanding O-Track Set Ups (<?php echo $totalRows_TMS_OutstandingOtrackSetUp ?>)</h2>
<?php if ($totalRows_TMS_OutstandingOtrackSetUp > 0) { // Show if recordset not empty ?>
<?php do { ?>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="71%" valign="top"><strong><?php echo $row_TMS_OutstandingOtrackSetUp['school_name']; ?></strong><br />
Responsible Officer: <?php echo $row_TMS_OutstandingOtrackSetUp['responsible_officer']; ?><br />
Pick Up Officer: <?php echo $row_TMS_OutstandingOtrackSetUp['otrack_data_pick_up_officer']; ?><br />
Pick Up Date: <?php echo date ('D jS M Y', strtotime ($row_TMS_OutstandingOtrackSetUp['otrack_data_pickup_date'])); ?> </p> </td>
<td width="29%" valign="top"><a href="taskdetail_otrack.php?recordID=<?php echo $row_TMS_OutstandingOtrackSetUp['id']; ?>">View</a></td>
<td width="29%" valign="top"><a href="delete_otrack.php?recordID=<?php echo $row_TMS_OutstandingOtrackSetUp['id']; ?>">Delete</a></td>
</tr>
</table>
<p>
<?php } while ($row_TMS_OutstandingOtrackSetUp = mysql_fetch_assoc($TMS_OutstandingOtrackSetUp)); ?>
<?php } // Show if recordset not empty ?>
<h2>Outstanding dataSEFs (<?php echo $totalRows_TMS_OustandingDataSEF ?>) </h2>
<?php if ($totalRows_TMS_OustandingDataSEF > 0) { // Show if recordset not empty ?>
<?php do { ?>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="71%" valign="top"><strong><?php echo $row_TMS_OustandingDataSEF['school_name']; ?></strong><br />
Responsible Officer: <?php echo $row_TMS_OustandingDataSEF['responsible_officer']; ?><br />
Data Received Date: <?php echo date ('D jS M Y', strtotime ($row_TMS_OustandingDataSEF['analysis_data_received_date'])); ?><br />
</p> </td>
<td width="29%" valign="top"><a href="taskdetail_analysis.php?recordID=<?php echo $row_TMS_OustandingDataSEF['id']; ?>">View</a></td>
<td width="29%" valign="top"><a href="delete_analysis.php?recordID=<?php echo $row_TMS_OustandingDataSEF['id']; ?>">Delete</a></td>
</tr>
</table>
<?php } while ($row_TMS_OustandingDataSEF = mysql_fetch_assoc($TMS_OustandingDataSEF)); ?>
<?php } // Show if recordset not empty ?>
<p> </p>
</div>
</div>
<div class="content_left_bottom">
</div>
</div>
<div class="content_right_pic">
<img src="../images/customer_right.jpg" alt="Girl Photo" width="278" height="197" /> </div>
<div class="content_right">
<div class="right_list">
<h1 class="fontface">Add New Task</h1>
</div>
<div class="right_list">
<div class="right_list_pic">
<img src="../images/aboutus/orb_blue.jpg" alt="orb" width="35" height="35" />
</div>
<div class="right_list_text">
<span class="style1"><a href="add_otrack.php">O-Track Set Up</a></span></div>
</div>
<div class="right_list">
<div class="right_list_pic">
<img src="../images/aboutus/orb_green.jpg" alt="orb" width="35" height="35" />
</div>
<div class="right_list_text">
<span class="style1"><a href="add_otrackreport.php">O-Track Report</a></span><br />
</div>
</div>
<div class="right_list">
<div class="right_list_pic">
<img src="../images/aboutus/orb_red.jpg" alt="orb" width="35" height="35" />
</div>
<div class="right_list_text">
<span class="style1"><a href="add_analysis.php">Analysis Report</a></span><br />
</div>
</div>
<div class="right_list">
<div class="right_list_pic">
<img src="../images/aboutus/orb_orange.jpg" alt="orb" width="35" height="35" />
</div>
<div class="right_list_text">
<span class="style1"><a href="add_misc.php">Misc</a></span><br />
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div class="footer_in">
<div class="footer_menu">
<ul>
<li><a href="../index.php">Home</a></li>
<li><a href="../products.php">Products</a></li>
<li><a href="../support.php">Support</a></li>
<li><a href="../customer.php" >Customer</a></li>
<li><a href="../contactus.php" >Contact us</a></li>
</ul>
</div>
<div class="footer_menu2">
<ul>
<li><img src="../images/footer/email.jpg" alt="email" /><span style="line-height:25px;"><?php echo $row_CompanyDetails['Email']; ?></span></li>
<li><img src="../images/footer/telephone.jpg" alt="telephone" /><span style="line-height:25px;"><?php echo $row_CompanyDetails['Telephone']; ?></span></li>
<li><img src="../images/footer/fax.jpg" alt="fax" /><span style="line-height:25px;"><?php echo $row_CompanyDetails['Fax']; ?></span></li>
</ul>
</div>
<div class="footer_right">
<a href="../terms.php">Terms</a> | <a href="../privacy.php">Privacy policy</a> | © <?php echo date('Y');?> Optimum Reports
<div class="footer_social">
<a href="https://twitter.com/OptimumReports" target="_blank"><img src="../images/footer/twiiter.jpg" alt="Twitter" /></a>
<a href="http://www.facebook.com/OptimumReports"><img src="../images/footer/facebook.jpg" alt="Facebook" /></a>
</div>
</div>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($CompanyDetails);
mysql_free_result($TMS_OutstandingOtrackSetUp);
mysql_free_result($TMS_OustandingDataSEF);
?>
Copy link to clipboard
Copied
You need to change the current query definition to something like this:
if ($colname_TMS_OustandingDataSEF = "All") {
$query_TMS_OustandingDataSEF = "SELECT * FROM tms WHERE task_type = 'dataSEF Analysis' AND signed_off = 'N'";
} else {
$query_TMS_OustandingDataSEF = sprintf("SELECT * FROM tms WHERE responsible_officer = %s AND task_type = 'dataSEF Analysis' AND signed_off = 'N'", GetSQLValueString($colname_TMS_OustandingDataSEF, "text"));
}
You've got two similar queries so you'll need to make a similar change in the other one.