ccutla Posted April 4, 2006 Share Posted April 4, 2006 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/phppages/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"> <br></td></tr></table></div><form method="post" action="http://mysql/phppages/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"> <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! Quote Link to comment Share on other sites More sharing options...
trq Posted April 4, 2006 Share Posted April 4, 2006 Most likely your query isn't stisfied. Maybe something like this would be more effective.[code]mysql_query(" SELECT * FROM $usertable WHERE ($metode = '%$search%' OR '%$search2%') OR ($metode2 = '%$search%' OR '%$search2%')");[/code] Quote Link to comment Share on other sites More sharing options...
ccutla Posted April 4, 2006 Author Share Posted April 4, 2006 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. Quote Link to comment Share on other sites More sharing options...
cattledogz Posted April 5, 2006 Share Posted April 5, 2006 Maybe try something like this (I use this on my "1 or 2 field" search):[code]$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 contentwhile($r=mysql_fetch_array($result)){//the format is $variable = $r["dbase"];$field1=$r["1"];$field2=$r["2"];$field3=$r["3"];//display the rowecho "your search results";}?> [/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.