Implementing an extendable search in PHP - might be confusing

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have a pup web page in which has a number of search fields at the top and
below that a set of results.

The results are related to the input search criteria

e.g. Imagine a DB table "stock_items"

When you enter in the search criteria field "Manufacturer" the item "Sony"
only items manufactured by Sony are shown below.

Pretty standard I'm sure. I've also added a bit of Ajax that when you click
on one of the results you get displayed full details of those results.

But that's as far as my Ajax goes at present.

I want to add the following facility. I want the user of the webpage to be
able to add more search criteria  if they choose to. For example, lets say
they wanted to add another manufacturer to be included in the search (lets
say "samsung") they could do this. (and in this case this would give results
of both samsung and Sony)

So in other words if they want to search on one particular field with more
then one value, they actually add another field to the search page.

I would want this process to be achieved by the user having the option of
selecting a special drop down box at the bottom of the search screen which
lists all the possible fields that are searchable.

If they select this, a corresponding data  entry field adjusts to be take
the input of the search field they just selected in the drop down box (so in
the case of manufacturer, this would just be a text box - but in other cases
it might be a list of limited choices )

The user can then enter the extra search criteria they want to search on (so
in this case they have added to search on "manufacturer" with the value

Now if they wanted to include another manufactory in the search they could
add another criteria in the same way.

So therefore they can add as many search criteria as they like.

Looking at which I have just written it probably is confusing as hell. I
tried to write it succinctly but it is hard.

The actual question I have (if you have followed what I'm after) is what is
the best way of achieving this? Has anyone implemented something like this
before and if so how did they go about it.

If this posting is just too confusing I will just have to look and find an
example somewhere.

Thank in advance

Re: Implementing an extendable search in PHP - might be confusing wrote:
Quoted text here. Click to load it

This shouldn't be that hard.  One way would be to just have the list box
as a multi-select.  It would be pretty simple to implement and the user
could easily remove search criteria.

Another way would be to keep track of the current selection criteria
(i.e. in your $_SESSION variable) and make changes based on the user

Either way, it's just a matter of building the SQL dynamically based on
selections from the user's input.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Implementing an extendable search in PHP - might be confusing

<> contained the following:

Quoted text here. Click to load it

It's quite simple to use the output of your form to build the SQL query.

However the mechanics of the search form seem bewildering.  You should
aim to make it as simple as possible for your users (even if this means
more coding for you).
Geoff Berrow  0110001001101100010000000110
100110001101101111001011100111010101101011 -

Re: Implementing an extendable search in PHP - might be confusing

On Apr 5, 6:36 pm, <> wrote:
Quoted text here. Click to load it

Hi, may I suggest that you sign your post in some fashion?
I generally tend to not answer posts where the author seems
to be overly anonymous.  Even a fake handle is better than
none at all.  In your case I see neither a name at the
bottom nor a From at the top.

Nevertheless, this particular question has some interesting
aspects.  There are actually a few issues involved.  One is
how the user can specify a search criteria in the web page,
another is the resulting internal representation, and then
how do you parse that and make the query.

I would suggest an eBay/Google combination for the "internal"
representation, which is not so internal since you can
have it be text inside an input (type=text) element.
Specifically, google allows you to specify a field by
prefixing the search criteria with "field:".  An example
would be
Both of them allow you to negate a criteria by prefixing it
with a "-".  Furthermore, ebay allows you to make a
primitive OR condition by enclosing field values within
parens a la:
dog (cat, fish)
which would select for those items that have the word dog
in them and either the word cat or fish.

You have seemed to imply that you'd like the user to be
able to specify this merely by clicking (as opposed to
having to type), which is not unreasonable for your situation
where the universe of possibilities is small.  However, you
can't do a multiple select listbox as a dropdown; therefore
a multi select element will take up more real estate.  There
is a possibility that you could use a drop down select
element as a toggle:
Select it once, and it adds the item.  Select it the next
time and it removes the item.  However, if you allow
freehand entry into the assumed textbox where the search is
appearing, then you will have to be very careful about
parsing it because users may put in all sorts of weird, but
otherwise legitimate queries.

I think in your place what I would do is to have a textbox
for the main search criteria (such as the item name or
description), and for restricted universe type of items
have a hidden input element which the user can't alter.
That having been said, though I've implemented the general
type of search form with field:..., I've not tried this
toggle mechanism that I described, so it might be a total

Csaba Gabor from Vienna

Site Timeline