Please help creating search result page of this search form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
prasitc2005
Forum Commoner
Posts: 42
Joined: Thu Jul 13, 2006 7:14 am

Please help creating search result page of this search form

Post by prasitc2005 »

Hi all php gurus

I have tried to build quite a complex search page having the search form like this in Dreamweaver PHP:

Search by category: drop down category 1 2 3
Search by details drop down like: size 1 2 3, colour 1 2 3, manufacture 1 2 3
Also containing text:....

How can I code a search result page that can show some products which can have category 1, size 1, colour 2 and contain the text "steel"
etc.

Please help soon! Thanks a lot!
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

  • Take the values you get from the form submission
  • Validate them
  • Escape them (with relevent escaping method supplied by database)
  • Build an SQL query with them that fetches the data using things like WHERE `field` LIKE 'value'
  • Fetch the data from the query
  • Format the data as output
matt1019
Forum Contributor
Posts: 172
Joined: Thu Jul 06, 2006 6:41 pm

Post by matt1019 »

hi prasitc,

just querying it in google gave me plenty of helpful tutorials....

http://www.google.com/search?hl=en&q=bu ... h%2Bengine

I am not an expert in php otherwise, i would have given you a quick/rough starting point as far as the code goes...

BUT, from my understanding of the php language, ole has given an excellent outline to follow.


hopefully this helps,

-Matt
User avatar
prasitc2005
Forum Commoner
Posts: 42
Joined: Thu Jul 13, 2006 7:14 am

Thanks

Post by prasitc2005 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Great guidance

Could you give me an example of scripts, please. Anything at all. I can't imagine how long they will be. Thanks!

well I couldn't go farer than this: This is partly just a simple approach. I'm stuck!

Code: Select all

<?
$colcid_rs_search_result = "1";
if (isset($_GET['cid'])) {
  $colcid_rs_search_result = (get_magic_quotes_gpc()) ? $_GET['cid'] : addslashes($_GET['cid']);
}
$colname_rs_search_result = "1";
if (isset($_GET['searchtext'])) {
  $colname_rs_search_result = (get_magic_quotes_gpc()) ? $_GET['searchtext'] : addslashes($_GET['searchtext']);
}
mysql_select_db($database_hydrosql, $hydrosql);
$query_rs_search_result = sprintf("SELECT flow_products.name, flow_products.material, flow_products.manufac, flow_products.detail, flow_products.image, flow_products.pdf, flow_cat.cat_name FROM flow_products inner join flow_cat on flow_products.cat_id =  flow_cat.cat_id WHERE name like '%%%s%%'  AND cat_name = '%s' ORDER BY flow_products.name ASC", $colname_rs_search_result,$colcid_rs_search_result);
$query_limit_rs_search_result = sprintf("%s LIMIT %d, %d", $query_rs_search_result, $startRow_rs_search_result, $maxRows_rs_search_result);
$rs_search_result = mysql_query($query_limit_rs_search_result, $hydrosql) or die(mysql_error());
$row_rs_search_result = mysql_fetch_assoc($rs_search_result);
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Tom420
Forum Newbie
Posts: 15
Joined: Sun Aug 13, 2006 1:50 am
Location: Sherbrooke, Québec, Canada

Post by Tom420 »

No one is going to write a script for you. You should simplify your problem into smaller problems (a programmer often call those 'functions'), and deal with each small problems at once. Go one to the next small problems when the first one is working.

When you get in trouble, read the related entry in the appropriate manual. If that fails, Google about the problem, search this forum for someone who had a similar problem, search other appropriate forums. In some case you might even try to split your problem into even smaller problems.

If everything fail, explain your problem here, on as small as possible a problem, as small as possible a code snippet, and as many as possible details. At that point, people will be happy to help. Not before that moment.

This is how forums work.

Hope this helps,
Tom :)
User avatar
prasitc2005
Forum Commoner
Posts: 42
Joined: Thu Jul 13, 2006 7:14 am

Post by prasitc2005 »

Thanks. I appreciate all instructions. Will try my best to solve the problems.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Hey, prasitc2005:
I wrote:Escape them (with relevent escaping method supplied by database)
OK?
User avatar
prasitc2005
Forum Commoner
Posts: 42
Joined: Thu Jul 13, 2006 7:14 am

Post by prasitc2005 »

Thanks for your concern, Ole. Your help is the most useful one so far.
matt1019
Forum Contributor
Posts: 172
Joined: Thu Jul 06, 2006 6:41 pm

Post by matt1019 »

hi prasitc,

did you try this?
viewtopic.php?t=24222

very very very informative!!! i learned something good (very good indeed) from this.

also check out the last post.... it has the link to another resource that will help you achieve your goal ;)

-Matt
User avatar
prasitc2005
Forum Commoner
Posts: 42
Joined: Thu Jul 13, 2006 7:14 am

How can I create result page from this search form?

Post by prasitc2005 »

Thanks Matt. Very useful but the last link was broken. PHP search is such a complex thing. Does anybody know how to do complex search like in Ebay?

How can I create result page from this search form?

Image
Tom420
Forum Newbie
Posts: 15
Joined: Sun Aug 13, 2006 1:50 am
Location: Sherbrooke, Québec, Canada

Post by Tom420 »

Actually you won't do your search with PHP, but with SQL (I'm guessing your data is stored in some database, not a flat file). PHP will just be used for manupulating the search data and display it on the screen.

Code: Select all

$result = mysql_query("SELECT * FROM digital_cameras WHERE type IS LIKE '$type' AND brand IS LIKE '$brand' AND resolution IS LIKE ........");
In SQL, 'any' is read as %, so

Code: Select all

WHERE type IS LIKE '%'
should do the trick.

for the keywords, your query will look like:

Code: Select all

SELECT * FROM digital_cameras WHERE type IS LIKE '%$keywords%' OR brand IS LIKE '%$keywords%'..............
Hope this is a good starting point for your quest, but this isn't an SQL forum, is it? :roll:

Tom :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Tom420 wrote:Hope this is a good starting point for your quest, but this isn't an SQL forum, is it?
PHP - Code is not an SQL forum, but Databases is.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

ole wrote:Build an SQL query with them that fetches the data using things like WHERE `field` LIKE 'value'
I really believe fulltext is easier and better for search engines. Like is very unpredictible and returns things like category when you search for cat. Not only that fulltext will take a string of words where like needs prefomatting.
Post Reply