Creating a search which collects data from MYSQL Database and displays.

Reply

Join Date: Oct 2009
Posts: 2
Reputation: J.M is an unknown quantity at this point 
Solved Threads: 0
J.M J.M is offline Offline
Newbie Poster

Creating a search which collects data from MYSQL Database and displays.

 
0
  #1
30 Days Ago
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
Last edited by J.M; 30 Days Ago at 5:59 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 35
Reputation: kekkaishi is an unknown quantity at this point 
Solved Threads: 5
kekkaishi kekkaishi is offline Offline
Light Poster
 
0
  #2
30 Days Ago
Originally Posted by J.M View Post
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,
  1. $postCode = $_POST['search'];
  2. $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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: J.M is an unknown quantity at this point 
Solved Threads: 0
J.M J.M is offline Offline
Newbie Poster
 
0
  #3
30 Days Ago
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
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro
 
0
  #4
30 Days Ago
Originally Posted by kekkaishi View Post
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,
  1. $postCode = $_POST['search'];
  2. $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.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Reply

Tags
data, display, mysql, php, search

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC