Forums

This topic is locked

Desperate for quick fix for search variable

Posted 30 Jun 2007 13:53:34
1
has voted
30 Jun 2007 13:53:34 Russell Isaac posted:
anyone out there kind enough to help with (hopefully) a quick pointer.

have a search page (for a dating site) which i am setting up a number of search criteria with drop-down menus, thru one form - i.e. select by age AND by hair colour AND by AGE etc. all working fine using variables, but i need to add an option for each search box to default to selecting ANY if the user doesnt want to make a choice i.e select age 25 to 30, hair ANY etc

i understand how the variables are passed but, for instance with HAIR i have a list of colours but cant see how to pass a default variable meaning ANY if the user doesnt select another option form the drop down box.

desperate to sort this by sunday night and really appreciate any pointers from anyone.

cheers!

Replies

Replied 30 Jun 2007 19:43:28
30 Jun 2007 19:43:28 Alan C replied:
I'm guessing a bit here - so this might be a bit off course.

At the top of each drop-down put something like 'Select hair colour' 'Select age' or just leave it as 'any' and a value against it too, so when that value gets passed into your script you will know that the user did not any select a particular colour etc. Then when you assemble your query you can leave out that item.

I wrote something similar as a function that built the query by adding more AND items onto it - you pass it the existing query and a string containing the new criteria, it checks if WHERE is present and adds it if necessary

<pre id=code><font face=courier size=2 id=code> # used to build a WHERE clause in archive_select, adds more criteria
# always checks whether WHERE has already been added
function buildWhere($where_string, $addition)
{
if (!strpos($where_string, 'WHERE'))
{
$where_string =' WHERE ';
}
else
{
$where_string.=' AND ';
}
return $where_string.$addition;
}
</font id=code></pre id=code>

hope that's of use
Replied 01 Jul 2007 10:01:04
01 Jul 2007 10:01:04 Russell Isaac replied:
thanks. i half-get where you're coming from and will take a look. appreciate you replying whatever!

Reply to this topic