Hi all,
I'm struggling to write an SQL query.
I'd like to search a database for either a person or an organisation.
I have an HTML form on a homepage, and this returns two values:
- a search term
- a search type, either 'person' or 'organisation'
code:
<form action="dir_query.php" method="post" name="qsearch" id="qsearch">
<table>
<tr>
<td>Searching for...</td>
<td><input type="text" name="dir_search" id="dir_search" /></td>
</tr>
<tr>
<td>which is...</td>
<td><select name="dir_type" id="dir_type">
<option value="organisation">an organisation's name</option>
<option value="person" selected>a person's name</option>
</select>
<input type="submit" value="submit" /></td>
</tr>
</table>
</form>
So far, so straightforward.
When processed these are converted into variables, and included in the MySQL query string.
The database, a contact list, has a number of fields, including name (a person's name) and organisation.
I'm currently trying:
$sql=(SELECT $dir_search FROM 'directory' WHERE $dir_type="person" OR $dir_type="organisation")
No dice. In fact, like this, no output at all. I've got a feeling that this will involve a table and an array, but then I start to palpitate.
Can anyone help?