Hi. I'm trying to search multiple DB fields with a Select Menu and I don't know where to start.

for example, from the code below I would like the value ='strAuthorname' to actually search the fields 'AuthorFirstName' AND 'AuthorLastName'.

<form method='post' action='{$_SERVER["PHP_SELF"]}'>
<!--select tag -->
<select name='metode' size='1' >
<option value='strTitle'>Title</option>
<option value='strMediatype'>Media Type</option>
<option value='strAuthorname'>Author</option>
<input type='text' name='search' value='{$search}' size='25'> &nbsp;

<input type='submit'   value ='search now'></p>


 if ($search !="" || $metode !="") {
// shoot off query
$res = mysql_query("SELECT * FROM tblpublications WHERE {$metode} LIKE '{$search}%'");

echo  "
//results here

Is this where I would use an array? I'm completely confused. Is this even possible?

thanks in advance!


9 Years
Discussion Span
Last Post by dottomm
$query = "select * from table where AuthorFirstName like '%$searchstring%' or AuthorLastName like '%$searchstring%'";

This will look for $searchstring in both AuthorFirstName and AuthorLastName fields. :) I hope thats what you want !


Thank you for your quick reply, but what I'm doing is using a select menu to choose what field the search query is looking in. However, I would like the select menu value to equal multiple values.

For instance, I would like the

<select name='metode' size='1' >
<option value='option1'>Option 1</option>
<option value='option2'>Option 2</option>
<option value='Author Name'>Author</option> <!--this value to search Author First Name &  Author Last Name Plus a Second Author First Name and Second Autor Last Names -->

so I want to set the select menu value 'Author Name' to search multiple data fields. Is this possible?


Yes. Possible.

if($_POST['metode'] == "Authorname") {
//if the user selects authorname from the list then use this query
$query = "select * from tablename where firstname like '%$searchtext%' or lastname like '%$searchtext%'";
} else {
   // else use other query 
Votes + Comments
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.