Jump to content


Photo

Why won't this search work?


  • Please log in to reply
3 replies to this topic

#1 ccutla

ccutla
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 04 April 2006 - 02:20 PM

I am trying to use this first html page using two different drop-down boxes to search a database and display the results, I can get it to work using a single drop-down, but when I try to use two seperate ones it doesn't return any results. Any help would be greatly appreciated, Thanks!


search.html:

<html>
<body>
<h1><center>Audit Database Search</center></h1>
<br><br><br><br>
<form method="post" action="http://mysql/phppage...es/results.php" target="_blank">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td bordercolor="#000000">
<p align="center">
<select name="metode" size="1">
<option value="DT_STRING">Date</option>
<option value="ACCOUNT">Account</option>
<option value="ACCOUNT_TYPE">Account Type</option>
<option value="CLIENT_ID">Client ID</option>
<option value="USER_ID">User ID</option>

</select> <input type="text" name="search" size="25"> &nbsp;<br>

</td>
</tr>
</table>
</div>

<form method="post" action="http://mysql/phppage...es/results.php" target="_blank">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td bordercolor="#000000">
<p align="center">
<select name="metode2" size="1">
<option value="DT_STRING">Date</option>
<option value="ACCOUNT">Account</option>
<option value="ACCOUNT_TYPE">Account Type</option>
<option value="CLIENT_ID">Client ID</option>
<option value="USER_ID">User ID</option>

</select> <input type="text" name="search2" size="25"> &nbsp;<br>
Search database: <input type="submit" value="Go!!" name="Go"></p>
</td>
</tr>
</table>
</div>
</form>
</form>
</body>

</html>



results.php:



<center>
<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">
<tr>
<td width="60"><b>DT_STRING</b></td>
<td width="100"><b>ACCOUNT</b></td>
<td width="30"><b>ACCOUNT_TYPE</b></td>
<td width="150"><b>CLIENT_ID</b></td>
<td width="150"><b>USER_ID</b></td>
</tr>
<tr>
<td>
<? $hostname = "mysql"; // The Thinkhost DB server.
$username = ""; // The username you created for this database.
$password = ""; // The password you created for the username.
$usertable = "AUDIT"; // The name of the table you made.
$dbName = "AUDITMED"; // This is the name of the database you made.

MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database");


//error message (not found message)begins
$XX = "No Record Found, to search again please close this window";

//query details table begins
$metode2 = $_POST['metode2'];
$metode = $_POST['metode'];
$search = $_POST['search'];
$search2 = $_POST['search2'];

$query = mysql_query("SELECT * FROM $usertable WHERE "$metode AND $metode2" = "'%$search%' AND '%$search2%'"");
while ($row = @mysql_fetch_array($query))
{
$variable1=$row["DT_STRING"];
$variable2=$row["ACCOUNT"];
$variable3=$row["ACCOUNT_TYPE"];
$variable4=$row["CLIENT_ID"];
$variable5=$row["USER_ID"];
//table layout for results

print ("<tr>");
print ("<td>$variable1</td>");
print ("<td>$variable2</td>");
print ("<td>$variable3</td>");
print ("<td>$variable4</td>");
print ("<td>$variable5</td>");
print ("</tr>");
}
//below this is the function for no record!!
if (!$variable1)
{
print ("$XX");
}
//end
?>
</table>
</center>


Grrr! I am out of ideas!

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 April 2006 - 04:05 PM

Most likely your query isn't stisfied. Maybe something like this would be more effective.
mysql_query("
  SELECT * FROM $usertable
  WHERE ($metode = '%$search%' OR '%$search2%')
  OR ($metode2 = '%$search%' OR '%$search2%')
");


#3 ccutla

ccutla
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 04 April 2006 - 04:43 PM

Well that was a good thought, but it didn't seem to work. Any other suggestions?? I don't know if my variables are wrong or what the deal is. Thanks anyways.

#4 cattledogz

cattledogz
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 05 April 2006 - 05:50 PM

Maybe try something like this (I use this on my "1 or 2 field" search):


$searchA=$_POST["field1"];
$searchB=$_POST["field2"];
$action=$_POST["action"];
if ( $action != '' ) {


$sql = "SELECT * FROM dbase WHERE searchA LIKE '%$field1%' AND searchB LIKE '%$field2%' ORDER BY field3 ASC LIMIT 0,1000";
$result = mysql_query($sql);

// uncomment the echo to see the query
//echo $sql;


//grab all the content
while($r=mysql_fetch_array($result))

{
//the format is $variable = $r["dbase"];

$field1=$r["1"];
$field2=$r["2"];
$field3=$r["3"];


//display the row

echo "your search results";
}
?>
      





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users