Jump to content

Archived

This topic is now archived and is closed to further replies.

ccutla

Trying to set up a search of mysql with multiple queries.

Recommended Posts

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"> &nbsp;<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!

Share this post


Link to post
Share on other sites
[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 :)

Regards
Liam

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.