ccutla Posted April 3, 2006 Share Posted April 3, 2006 This is my first post, I am just looking for a little help. I have a script that successfully searches a sql server one query at a time, but I want to be able to search by more than one column of the database and return a report. This is what I have so far as my search and results pages go...php:(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>Search database: <input type="submit" value="Go!!" name="Go"></p></td></tr></table></div></form></body></html>Which then returns the results using this page (results.php):php:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><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"; $username = ""; $password = ""; $usertable = "";$dbName = ""; 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$metode = $_POST['metode'];$search = $_POST['search'];$query = mysql_query("SELECT * FROM $usertable WHERE $metode LIKE '%$search%'"); 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>"); }if (!$variable1){ print ("$XX} //end ?></table></center>Any tips or suggestions would be greatly appreciated, thanks! Link to comment https://forums.phpfreaks.com/topic/6479-trying-to-set-up-a-search-of-mysql-with-multiple-queries/ Share on other sites More sharing options...
shocker-z Posted April 3, 2006 Share Posted April 3, 2006 [code]$query = mysql_query("SELECT * FROM $usertable WHERE $metode IN (SELECT field1, field2, field3 FROM $usertable)");[/code]just change the fields and that should work mate :)RegardsLiam Link to comment https://forums.phpfreaks.com/topic/6479-trying-to-set-up-a-search-of-mysql-with-multiple-queries/#findComment-23492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.