Forums
This topic is locked
Multiple Search Fields
Posted 13 Sep 2007 18:03:38
1
has voted
13 Sep 2007 18:03:38 EriK Miller posted:
I'm attempting to do multiple field search on a recordset that hold information about IT Projects. In the .html form the method is post. The results page code is posted below. What am I doing wrong? I can't see any issues. If I change th SQL to use OR instead of AND I get all of the records. Which is certainly NOT what I want. Any help you can provide would be greatly appreciated.<pre id=code><font face=courier size=2 id=code>
<?php require_once('../Connections/is_request.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;
}
}
$varMonth_Search = "*";
if (isset($_REQUEST["objectiveGoLiveMonth"])) {
$varMonth_Search = $_REQUEST["objectiveGoLiveMonth"];
}
$varSponsor_Search = "*";
if (isset($_REQUEST["projectSponsor"])) {
$varSponsor_Search = $_REQUEST["projectSponsor"];
}
$varName_Search = "*";
if (isset($_REQUEST["projectName"])) {
$varName_Search = $_REQUEST["projectName"];
}
$varManager_Search = "*";
if (isset($_REQUEST["projectManager"])) {
$varManager_Search = $_REQUEST["projectManager"];
}
$varOwner_Search = "*";
if (isset($_REQUEST["projectOwner"])) {
$varOwner_Search = $_REQUEST["projectOwner"];
}
mysql_select_db($database_is_request, $is_request);
$query_Search = sprintf("SELECT projectID, requestDate, projectName, projectSponsor, projectOwner, projectManager, objectiveGoLiveDay, objectiveGoLiveMonth, objectiveGoLiveYear FROM isproject WHERE isproject.projectName LIKE %s AND isproject.projectSponsor LIKE %s AND isproject.projectOwner LIKE %s AND isproject.projectManager LIKE %s AND isproject.objectiveGoLiveMonth LIKE %s", GetSQLValueString($varName_Search, "text",GetSQLValueString($varSponsor_Search, "text",GetSQLValueString($varOwner_Search, "text",GetSQLValueString($varManager_Search, "text",GetSQLValueString($varMonth_Search, "text");
$Search = mysql_query($query_Search, $is_request) or die(mysql_error());
$row_Search = mysql_fetch_assoc($Search);
$totalRows_Search = mysql_num_rows($Search);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search Results</title>
<style type="text/css">
<!--
.style1 {font-size: 12px}
-->
</style>
</head>
<body>
<table width="700px" align="center" style="background-image: url(images/sr_tr_background.jpg); padding: 10px; background-repeat: no-repeat; color:#FFFFFF; font-family: Arial, Helvetica, sans-serif;">
<tr>
<td align="center" width="5%">ID</td>
<td align="center" width="15%">Request Date</td>
<td align="center" width="30%">Project Name</td>
<td align="center" width="15%">Sponsor</td>
<td align="center" width="15%">Owner</td>
<td align="center" width="10%">Manager</td>
<td align="center" width="10%">Go Live</td>
</tr>
</table>
<table width="700px" align="center" style="background-image: url(images/sr_list_background.jpg); padding: 10px; background-repeat: no-repeat; color:#000000; font-family: Arial, Helvetica, sans-serif; height: 600px;">
<tr>
<td align="center" width="5%"><span class="style1"><?php echo $row_Search['projectID']; ?></span></td>
<td align="center" width="12%" nowrap="nowrap"><div style="overflow: hidden;"><?php echo $row_Search['requestDate']; ?></div></td>
<td align="center" width="30%"><a class="style1"><?php echo $row_Search['projectName']; ?></a></td>
<td align="center" width="15%"><span class="style1"><?php echo $row_Search['projectSponsor']; ?></span></td>
<td align="center" width="15%"><span class="style1"><?php echo $row_Search['projectOwner']; ?></span></td>
<td align="center" width="10%"><span class="style1"><?php echo $row_Search['projectManager']; ?></span></td>
<td align="center" width="10%"><?php echo $row_Search['objectiveGoLiveMonth']; ?> / <?php echo $row_Search['objectiveGoLiveDay']; ?> / <?php echo $row_Search['objectiveGoLiveYear']; ?></td>
</tr>
<tr>
<td colspan="7" align="center"><h3>Sorry your search did not return any results </h3></td>
</tr>
<tr>
<td align="center" colspan="7"><p><a href="results.php">View All</a></p>
<p><a href="search.php">Back to Search</a></p></td>
</tr>
<tr>
<td colspan="7" style="height: 100%;" align="center"> Previous
Next </td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($Search);
?>
</font id=code></pre id=code>