Hi There,
I have had a look on the internet but not really been able to find the correct thing i'm looking for very easily, or at least not very well/easily explained.

I am trying to create a Search Form for my website which has 2 fields.

1) A Postcode Field.
and 2) a Category drop down Menu

When the user clicks search the search should enter a MYSQL table on my database and find the postcode entered and the selected category fields and display the results along with additonal information such as address and telephone number.

For instance.
I search L21 2AG
and pick the Category: Cafe

The search then brings up 3 results (for example)

1) LS1 2AG - Cafe - 12 Main Street, Leeds - 01313135432
2) LS1 2AG - Cafe - 16 The Green, Leeds - 01313352124
3) LS1 2AG - Cafe - 90 Grove Street, Leeds - 013131242342

Anyone got any idea's.
Any code I can use, and websites for tutorials or something maybe.
I have a basic idea of the code Im going to require, not not very detailied idea.

Thankyou very much, I do hope you can help me.
Also I hope this was posted in the correct post, I've used this website numerous times before but only just created an account and posted.

Cheers,
Jordan


EDIT: Also I understand I may need a search.php file to proccess this? Cheers

Hi There,
I have had a look on the internet but not really been able to find the correct thing i'm looking for very easily, or at least not very well/easily explained.

I am trying to create a Search Form for my website which has 2 fields.

1) A Postcode Field.
and 2) a Category drop down Menu

When the user clicks search the search should enter a MYSQL table on my database and find the postcode entered and the selected category fields and display the results along with additonal information such as address and telephone number.

For instance.
I search L21 2AG
and pick the Category: Cafe

The search then brings up 3 results (for example)

1) LS1 2AG - Cafe - 12 Main Street, Leeds - 01313135432
2) LS1 2AG - Cafe - 16 The Green, Leeds - 01313352124
3) LS1 2AG - Cafe - 90 Grove Street, Leeds - 013131242342

Anyone got any idea's.
Any code I can use, and websites for tutorials or something maybe.
I have a basic idea of the code Im going to require, not not very detailied idea.

Thankyou very much, I do hope you can help me.
Also I hope this was posted in the correct post, I've used this website numerous times before but only just created an account and posted.

Cheers,
Jordan


EDIT: Also I understand I may need a search.php file to proccess this? Cheers

ok, lets say u name search field 'search' and the drop-down menu for 'cat'. and make the form POST all info to search.php (method POST action search.php).
In the search.php, the first thing u need to do is to retrieve the posted info.
for example,

$postCode = $_POST['search'];
$cat = $_POST['cat'];

Having done that, u need to query the database. you may want to SELECT all from your postcodestable WHERE postCode = $postCode AND category = $cat and display all info.
If you don't know how to do this, I suggest you to take this tutorial at http://www.tizag.com/mysqlTutorial/mysqlquery.php. Have a skim thru all the links. :)

Hi There,
Thanks Kekkaishi, I have more of an understanding now.
I've also been having a look at that link you supplied.

Could you, or possibly someone supply me with the code which I will be able to query the database and SELECT the information like you talked about, and then display the data?

Also what code would I need for the search form and for it too use the POST action to search.php?

I have done theese sort of things before, but it was long ago and I have forgotton theese things, but I do have a general idea of what you are talking about so not completey clueless haha :)..

If anyone could help me with the above it would be greatly appreicated.
Thanks again Kekakishi and Ill have a more indepth look at that link you supplied me, it does look very useful from what I can see!

Thankyou,
J.M

ok, lets say u name search field 'search' and the drop-down menu for 'cat'. and make the form POST all info to search.php (method POST action search.php).
In the search.php, the first thing u need to do is to retrieve the posted info.
for example,

$postCode = $_POST['search'];
$cat = $_POST['cat'];

Having done that, u need to query the database. you may want to SELECT all from your postcodestable WHERE postCode = $postCode AND category = $cat and display all info.
If you don't know how to do this, I suggest you to take this tutorial at http://www.tizag.com/mysqlTutorial/mysqlquery.php. Have a skim thru all the links. :)

First, I would not suggest querying the database with POST values, at least run them through mysql_real_escape_string first.

Also, with Postcodes people will not always enter them in the saem format, for example, postcodes may be entered in multiple ways:
AB123CD
AB 123 CD
AB123 CD
AB12 3CD

So I would suggest removing spaces from the POST data before querying and also having the values in the database with no spaces, or use a replace command in the query to remove them for the search. Otherwise there is a chance that you may not get results when you should.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.