Jump to content


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


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...

<h1><center>Audit Database Search</center></h1>
<form method="post" action="http://mysql/phppages/results.php" target="_blank">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0">
<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>

Which then returns the results using this page (results.php):


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">
<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>
<? $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))
//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

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 :)


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.