hello!
I hope someone can help me! I'm trying to make a search box for my hotel search site...
I have a big database with field names such as Town, City, and then also lots of fieldnames indicating each hotel's facilities, like Tennis, Creche, Restaurant.... The values in these latter fields are either Y or N.
I want to allow users to enter a town/city in one input box, and then one or more keywords (eg. creche, tennis) in a second inbox, and then click submit. My code for the search box so far looks like this:
<?php
//create search form
echo "<form action='searchresults.php' method='post'>
<tr>
<td class=\"lineheight\" height=\"4\"> </td>
<td align=\"right\" rowspan=\"5\" valign=\"top\" width=\"45\" class=\"searcharrow\">
<input type=image src=\"http://www.hotelheaven.co.uk/searcharrow.gif\" border=\"0\">
</td>
</tr>
<tr>
<td valign=\"top\" class=\"welcomewhite\">
Town/City<br>
<input type=\"text\" name=\"search\" class=\"searchbox\" size=\"26\">
</td>
</tr>
<tr>
<td class=\"lineheight\" height=\"2\"> </td>
</tr>
<tr>
<td valign=\"top\" class=\"welcomewhite\" width=\"142\">Keywords<br>
<input type=\"text\" name=\"keywords\" class=\"searchbox\" size=\"26\">
</td>
</tr>
</form>"
?>
and for calling the results on the next page i have:
$place = $_POST['search'];
$keywords = $_POST['keywords'];
$query = "SELECT Region FROM hotel WHERE (Town LIKE '$place' OR County LIKE '$place') OR fieldnames LIKE '%$keywords%'ORDER BY $sortBy LIMIT $offset, $limit";
My first question is - is there a generic word for all fieldnames? I know i can't just write "fieldnames", but there are about 100 of them - do i have to list each one separately in my select query??
I also know i need to include an AND field value = "Y" type bit - but i'm not sure how to word this either....
My second question is - have i got the general gist of what needs to be done? Say someone writes in 'creche, tennis' - I only want hotels that match for creche AND tennis, not one or the other!
In fact, i have a lot of questions like this and don't expect everyone to answer it all for me! honest! i really think i need a decent tutorial but have been searching all day and not found one that suits - i'd be really grateful if anyone could point me towards one!
Any help at all would be much appreciated! Thanks!
LizzyD