Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Posts
    178
    Plugin Contributions
    0

    Default Custom search and custom search URL.

    I have created a custom search page. After selecting info from several drop down boxes, a query searches the PRODUCTS table and compiles a list of products_model numbers. It then adds them to the end of the advanced_search URL.

    /index.php?main_page=advanced_search&search_in_description=1&keyword=6171 6175 6182 6189

    But, running this URL gives this message, "There is no product that matches the search criteria."

    I assume it is in need of something between each of the products_model numbers in the URL. What would be the proper way to construct the URL before allowing the user to link to the advanced search page? I tried adding OR between each number, but then it gives incorrect results. It will show number 6171 as well as 16171 and 61715. I tried single and double quotes, but both failed.

  2. #2
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Custom search and custom search URL.

    Quote Originally Posted by RFree190 View Post
    /index.php?main_page=advanced_search&search_in_description=1&keyword=6171 6175 6182 6189

    But, running this URL gives this message, "There is no product that matches the search criteria."
    Spaces aren't allowed in URL's

    That won't be your entire problem though. Even if/when you add a delimiting character to remove the spaces you'll need to modify the advanced search page so that it can retrieve and act upon the individual 'keywords'.

    Quote Originally Posted by RFree190 View Post
    What would be the proper way to construct the URL before allowing the user to link to the advanced search page? I tried adding OR between each number, but then it gives incorrect results. It will show number 6171 as well as 16171 and 61715. I tried single and double quotes, but both failed.
    Try something like this:
    // create URL
    $URL = /index.php?main_page=advanced_search&search_in_description=1 ;
    $temp = urlencode(6171 6175 6182 6189) ;
    $URL .= "&keyword=".$temp ;

    Then on the advanced search page:
    // decode URL
    $matches = $_GET('keyword') ;
    $keywords = preg_split("/ /",urldecode($matches));

    // this will produce a keywords array like:
    Array (
    [0] => 6171
    [1] => 6175
    [2] => 6182
    [3] => 6169
    )

    You can then use the array values to create your SQL query string, something like
    SELECT * from 'some_table' WHERE 'productID LIKE '$keywords[0]' OR 'productID LIKE '$keywords[1]' OR 'productID LIKE '$keywords[2]' OR 'productID LIKE '$keywords[3]' ;

    This is just 'off the top of my head' - It may or may not work as advertised, and there are several other methods that you can use rather than urlencode/decode (which is probably an overkill in this situation). Likewise, there are several other methods that you can use to isolate the individual 'keyword' components rather than preg_split. It would also be advisable to create the 'SELECT' string as a variable rather than 'hard coding' the keyword array data, especially since you are unlikely to know in advance how many keywords there will be in any given query/request.

    In short, what I've given you is an idea as to the principle requirements needed to make it work. The exact implementation can take many different forms.
    The most important thing to realize is that URL's cannot contain spaces.

    Cheers
    Rod

 

 

Similar Threads

  1. Custom Advanced Search Page URL
    By xixiwyhs in forum General Questions
    Replies: 4
    Last Post: 2 Feb 2016, 04:28 PM
  2. v151 Need to add custom form and advanced search to a new page
    By webmiss in forum General Questions
    Replies: 8
    Last Post: 20 Mar 2013, 01:32 PM
  3. Extra Search fields in custom Search form
    By jeffiec in forum Code Collaboration
    Replies: 2
    Last Post: 14 Mar 2013, 01:19 AM
  4. Linking search function to custom CSS search box
    By seeinteriors in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 1 Jun 2012, 10:52 PM
  5. Custom search text and button layout.
    By Develop&Promote in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 14 Jul 2010, 09:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg