Jump to content


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

  • Please log in to reply
1 reply to this topic

#1 ccutla

  • Members
  • PipPip
  • Member
  • 19 posts

Posted 03 April 2006 - 02:52 PM

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/phppage...es/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!

#2 shocker-z

  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 03 April 2006 - 03:09 PM

$query = mysql_query("SELECT * FROM $usertable WHERE $metode IN (SELECT field1, field2, field3 FROM $usertable)");

just change the fields and that should work mate :)

www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users