Forums

PHP

This topic is locked

Need help with PHP search page

Posted 11 Jul 2003 21:18:06
1
has voted
11 Jul 2003 21:18:06 LL Smith posted:
I am attempting to create a search page and a results page for my site using Dreamweaver MX and PHP with a MySQL database, Apache server and Windows 98. When I view the search page in the browser and run a search, the results page appears but it is empty. I have tested the results page and it appears to be functioning correctly but for some reason the results page will not display the information from the database.

Can anyone tell me what I am doing wrong?

Thanks in advance for your help!

Replies

Replied 14 Jul 2003 14:41:17
14 Jul 2003 14:41:17 Julio Taylor replied:
It's hard to tell. Can you post the SQL queries you're using and maybe some of the PHP you're using to display the results?

-- J

------------------------
Julio

PHP | MySQL | DWMX

ICQ: 19735247
MSN:
Replied 17 Jul 2003 19:01:35
17 Jul 2003 19:01:35 Shane Kelly replied:
I would make sure of two things on your search page:

1. Make sure it is set to POST
2. Make sure the action is set to your results page (i.e. results.php)
3. Give your fields unique names like mysearchfield, and give the form itself a unique name like mysearchform (no spaces)


Then make sure on your results page that your recordset is filtering the results based on a URL Variable or a FORM variable (your choice), and if it is searching the database on a text field entry, use the 'contains' attribute in your filter or if it is based on a drop-down list, you can leave it as '='
Replied 17 Jul 2003 19:02:52
17 Jul 2003 19:02:52 Shane Kelly replied:
That should give the results required....search and results are one of the easier PHP pages to do...there isn't a whole lot of code involved.
____________
Shane Kelly
Replied 29 Jul 2003 15:06:01
29 Jul 2003 15:06:01 Terry Ashley replied:
<font face='Verdana'>Are there any good tutorials out there to create a search field using DWMX and PHP, specifically I want to create a search criteria based on a dynamic menu, but I need to the basics of how to set search up in Dreamweaver first.</font id='Verdana'>

Terry D. Ashley
"Imagination is more important than knowledge." ..Albert Einstein
Replied 29 Jul 2003 15:36:05
29 Jul 2003 15:36:05 Shane Kelly replied:
There are lots of good resources out there...try phpbuilder.com see if you can find examples there...

The nuts and bolts of it is:

1. You need to create the search page. This page will have a form on it. Maybe name it fmsearch. Inside your form you can have all sorts of fields (including the dynamic field you were talking about) and include a submit button. In the action window for the form use something like search_results.php and use POST to pass the data to the results screen visibly (for debugging purposes).

2. Create the page search_results.php. This page is very simple. Create a new recordset in DWMX. Name it getSearchResults, point it to your connection string, choose the table you want to search from, leave columns all, and select filter then choose one of the searchable fields you're looking for, set it to contains if you want a fuzzy search or leave it as equal if you want exact results or no results, choose either URL Parameters and enter your field name from the previous page's form or use FORM value and the field name from the previous FORM. Now it gets a little more tricky. Click on the advanced tab. Write down all the fields you are searching on for example lets say you are doing a simple search of a persons first name, last name, and email address, and province/state (from a dynamic dropdown menu) in a database table called addresses that contains fields FIRSTNAME, LASTNAME,EMAIL,PROVINCESTATE. You have created a form called fmsearch, and on there have fields first_name, last_name, email, and province_state. This form is on a page called search.php. The form points to search_results.php. On the search_results.php page, you create a recordset called getResults, point it to your connection script (say connPersonnel) from the addresses table, select all, and then choose Filter: FIRSTNAME -&gt; Contains or Equal your choice -&gt;URL Parameter -&gt;first_name.

Now click Advanced mode...you should see something like this:

SELECT *
FROM addresses
WHERE FIRSTNAME LIKE '%colname%'

and below that in variables colname -1 $HTTP_GET_VARS['first_name']

Now what you have to do is add all the variables you want to search for ...so click the plus sign and enter

colname2 -1 $HTTP_GET_VARS['last_name']
colname3 -1 $HTTP_GET_VARS['email']
colname4 -1 $HTTP_GET_VARS['province_state']

(where the names inside the [' '] are the names from the search form (not the database))

Then manually edit the SQL statement to say:

SELECT *
FROM addresses
WHERE FIRSTNAME LIKE '%colname%' AND LASTNAME LIKE '%colname2%' AND EMAIL = 'colname3' AND PROVINCESTATE = 'colname4'

And thats about it...notice that if you are using equal you dont include the % signs...and you probably want them to do an exact search on the email and province/state fields because there are only so many options...where as if they put in Chris for the first name and it is in the database as Christopher...it will still pick them up.

Then simply create a table, and insert the fields from your record set into the table, and possibly add repeat region behaviours if there will be more than one result, and even some navigational buttons for more records.

Hope that helps.

kellydigital

Reply to this topic