Forums

PHP

This topic is locked

SEARCH/RESULTS Question

Posted 17 Feb 2002 08:50:59
1
has voted
17 Feb 2002 08:50:59 John Ashton posted:
Hi All, Novice here.
I have a search form where the user enters a name, then selects one of two columns from which to search. Thus the form sends URLstuff...?name=value,column=value.

My problem is I cant figure out how to set up the query. I am using Phakt, PHP & MySQL.

Any guidance would be really much appreciated.



John Ashton
Intellinet Business Solutions
Wollombi NSW 2325
ph: +61-2-4998 3426
website: www.intellinet.com.au
email:

Replies

Replied 17 Feb 2002 11:46:35
17 Feb 2002 11:46:35 Bruno Mairlot replied:
To setup the query, use the Recordset server behavior.

Then, in the Filter drop-down menu, select the field of the database you want to search, then, select the URL Get Parameter, then close to that menu, you will just enter the name of the URL Get parameter (name or column as in your example)

If you want to search on more than one field, then switch to Advanced view, there you will see the SQL statement, in the WHERE part, add your second field, and don't forget to add a Parameter.

Hope it helps.

Bruno

--- Better to die trying, than never try at all ---
Replied 18 Feb 2002 02:06:29
18 Feb 2002 02:06:29 John Ashton replied:
Bruno
Many thanks for your prompt reply, but it looks like I did not explain the problem sufficiently, or, I am missing something in your answer.

The database contains a number of columns, two of which contain names that can be searched on. (FamilyName & Ship). Now, the Search form allows the user to enter a name to be searched on and selects either FamilyName or Ship. Therefore, the query has to be set up so that it can search for the "value" given to the "Name" field in the form, AND the "value" given to the "columnSelect" field in the form.

My problem is I cant figure out the PHP and/or the MySQL code to search for the name entered given that it may be contained in one column OR the other subject to the selection taken by the user.

The form passes two variable pairs, Name=value and columnSelect=value. The value for "columnSelect" needs to be changed into a "name" and the value passed with "Name" needs to be associated with the newly created name for the selected column. Hence what I should end up with is a new name/value pair that looks like selectedColumn=nameEntered.

One approach I considered was to have two record sets. One for each condition, (ie: one for FamilyName and one for Ship) but I could not work out the php/mysql to select the required recordset using an if statement.

Regards

John.

<u></u><font color=green></font id=green>

John Ashton
Intellinet Business Solutions
Wollombi NSW 2325
ph: +61-2-4998 3426
website: www.intellinet.com.au
email:
Replied 18 Feb 2002 11:12:39
18 Feb 2002 11:12:39 Bruno Mairlot replied:
OK, now I see more clearly what you need...

When defining the Recordset, use the Advanced View.

Then, you will define two Paramater (in the list down to the query textearea). The definition of the parameter should look like :

MM_ColParam1 : <font color=red>$HTTP_POST_VARS["columnSelect"]</font id=red> while the other will be
MM_ColParam2 : <font color=red>$HTTP_POST_VARS["Name"]</font id=red>

Then, in your query statement, enter the following in the WHERE statement :

SELECT * FROM yourTable
WHERE MM_ColParam1='MM_ColParam2'

Therefore, on the input named 'Name' (which isn't a good input name), the user will enter the name he wants to search, then select the column he wants to search on.

Suppose the Name value is 'Bruno' and the column is 'FamilyName' the query will look like :

SELECT * FROM yourTable WHERE FamilyName='Bruno'

if the user select the column 'Ship' the query will be

SELECT * FROM yourTable WHERE Ship='Bruno'


Of course, you will need to change the table name and selected fields according to your DB specification, but in essence, it is there..

Hope it helps.

Bruno


--- Better to die trying, than never try at all ---
Replied 19 Feb 2002 03:24:45
19 Feb 2002 03:24:45 John Ashton replied:
Bruno

sorry for the confusion with the name "name".


<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>When defining the Recordset, use the Advanced View.

Then, you will define two Paramater (in the list down to the query textearea). The definition of the parameter should look like :

MM_ColParam1 : $HTTP_POST_VARS["columnSelect"] while the other will be
MM_ColParam2 : $HTTP_POST_VARS["Name"]

<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

OK. One more time for the dummies. I dont understand what you mean by this. Can you explain it a little more please. Where does this go exactly.

Additionally, If I were to change the WHERE portion of the SELECT statement in the SQL section of the Advanced Recordset dialog box, wouldn't I get an error as MM_ColParam1 is not a defined column in the database.

Best Regards
John.

Reply to this topic