Page 1 of 1
Please help creating search result page of this search form
Posted: Sat Aug 12, 2006 3:05 pm
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!
Posted: Sat Aug 12, 2006 5:36 pm
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
Posted: Sat Aug 12, 2006 6:43 pm
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
Thanks
Posted: Sat Aug 12, 2006 6:43 pm
by prasitc2005
feyd | Please use 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
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]
Posted: Sun Aug 13, 2006 12:36 pm
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

Posted: Sun Aug 13, 2006 12:52 pm
by prasitc2005
Thanks. I appreciate all instructions. Will try my best to solve the problems.
Posted: Sun Aug 13, 2006 3:08 pm
by Ollie Saunders
Hey, prasitc2005:
I wrote:Escape them (with relevent escaping method supplied by database)
OK?
Posted: Sun Aug 13, 2006 3:27 pm
by prasitc2005
Thanks for your concern, Ole. Your help is the most useful one so far.
Posted: Mon Aug 14, 2006 9:41 pm
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
How can I create result page from this search form?
Posted: Wed Aug 16, 2006 6:29 am
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?

Posted: Wed Aug 16, 2006 4:58 pm
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
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?
Tom

Posted: Wed Aug 16, 2006 5:03 pm
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.
Posted: Wed Aug 16, 2006 5:31 pm
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.