Guest Posted December 7, 2005 Posted December 7, 2005 I installed the contribution for Product Extra Fields (I posted to that support forum and didn't get a response, so I thought I'd try here) and would like to add an Author search and a Title search to my advanced_search.php page. I added the fields to that page without problem and tried to write the code on advanced_search_results.php to make it work, but no luck. Even though the keyword search will pick up author, my client wants a separate author search field on the advanced search page. Can anyone help me write these lines correctly? Here's the code from lines 61 and 281 in advanced_search_results.php. I keep getting No Products Match with this version of the code. Around line 61: if (isset($HTTP_GET_VARS['author'])) { $author = $HTTP_GET_VARS['author']; } Around line 281: if (isset($author) && (sizeof($author) > 0)) { $where_str .= " and p.products_author like '%" . tep_db_input($author) . "'"; } I made some changes to more code and now get every product in the store returned as a result. Around line 289: if (isset($search_author) && (sizeof($search_author) > 0)) { $author = tep_db_prepare_input($search_author[$i]); $where_str .= " and p.products_author like '%" . tep_db_input($author) . "%'"; } Around line 128: if (tep_not_null($author)) { if (!tep_parse_search_string($author, $search_author)) { $error = true; $messageStack->add_session('search', ERROR_INVALID_KEYWORDS); } }
kgt Posted December 7, 2005 Posted December 7, 2005 Right after the line $listing_sql = $select_str . $from_str . $where_str . $order_str; add this: echo '<br>'.$listing_sql.'<br>'; Is the sql what your expect to see? If not, it'll probably give you a hint of what's going wrong. Contributions Discount Coupon Codes Donations
Guest Posted December 8, 2005 Posted December 8, 2005 Good advice. The sql isn't what I expect. I assume that the problem lies where it says author like %%, but I don't know how to fix that. I'm guessing that it's not grabbing the data from the author field. The code from the advanced_search.php page for the author box is (SQL statement follows it) $info_box_contents[] = array('text' => tep_draw_input_field('author', '', 'style="width: 80%"')); new infoBox($info_box_contents); $info_box_contents = array(); select distinct p.products_image, m.manufacturers_id, p.products_author, p.products_mediatype, p.products_genre, p.products_bestseller, p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from products p left join manufacturers m using(manufacturers_id), products_description pd left join specials s on p.products_id = s.products_id, categories c, products_to_categories p2c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p.products_author like '%%' order by pd.products_name
kgt Posted December 8, 2005 Posted December 8, 2005 I think you're confused about what sizeof() does. It's an alias for count(). See: http://us3.php.net/manual/en/function.count.php Specifically the part: "If var is not an array or an object with implemented Countable interface, 1 will be returned. There is one exception, if var is NULL, 0 will be returned." sizeof() expects an array, and will return 1 for ANY string. Here's where that '%%' part of your query is being generated: if (isset($search_author) && (sizeof($search_author) > 0)) { $author = tep_db_prepare_input($search_author[$i]); $where_str .= " and p.products_author like '%" . tep_db_input($author) . "%'"; } sizeof( $search_author ) == 1 even if $search_author == '' To get the length of a string, use strlen(): http://us3.php.net/manual/en/function.strlen.php Contributions Discount Coupon Codes Donations
Guest Posted December 8, 2005 Posted December 8, 2005 I switched sizeof to strlen and I'm still getting the %% and all the products in the store. (I got sizeof by copying and modifying the lines on searching keyword because modifying the code for manufacturer_id didn't seem to get me anywhere) if (isset($search_author) && (strlen($search_author) > 0)) { $author = tep_db_prepare_input($search_author[$i]); $where_str .= " and p.products_author like '%" . tep_db_input($author) . "%'"; }
kgt Posted December 9, 2005 Posted December 9, 2005 if (isset($search_author) && (strlen($search_author) > 0)) { $author = tep_db_prepare_input($search_author[$i]); $where_str .= " and p.products_author like '%" . tep_db_input($author) . "%'"; } I'm sorry, I just noticed this: $search_author[$i] Is $search_author really an array? Even if it is, where is it being set? I think you need to post all of advanced_search_results.php and also the snippets like $info_box_contents[] = array('text' => tep_draw_input_field('author', '', 'style="width: 80%"')); new infoBox($info_box_contents); $info_box_contents = array(); Where you create the search form. It's just too confusing trying to piece together the pieces. Contributions Discount Coupon Codes Donations
Guest Posted December 10, 2005 Posted December 10, 2005 Aha! You're right - search_author isn't an array. In fact, I shouldn't have been using search_author at all. I played around with it some more and got it to work by changing it to: if (isset($author) && (strlen($author) > 0)) { $author = tep_db_prepare_input($author); $where_str .= " and p.products_author like '%" . tep_db_input($author) . "%'"; } Thanks very much for your helpful pointers!
Guest Posted February 7, 2006 Posted February 7, 2006 I am trying to add dropdowns to the advanced search page that will search in specific hard coded fields. I am using the code on this thread in advanced_search_results.php. When I search, advanced_search_results.php displays all of the products in the category I am searching in, not just the items matching the search query. I think I may be passing the search variables incorrectly from advanced_search.php. I created html form dropdowns with names matching the names of the extra fields. Here is the code I am using (the file names are different, but they are advanced_search.php & advanced_search_results.php) Advanced Search: http://www.seocorp.com/example_advanced_search.htm Here are the form fields I have added: <input type="hidden" name="categories_id" value="8" /> <input type="hidden" name="keywords" value="*" /></td> <td><select name="housing_length"> <option value="*">*</option> <option value="28">28</option> <option value="30">30</option> <option value="32">32</option> <option value="32 1/2">32 1/2</option> <option value="34">34</option> </select></td> <td><select name="travel_length"> <option value="*">*</option> <option value="4 3/4">4 3/4</option> <option value="4 3/8">4 3/8</option> <option value="4 5/16">4 5/16</option> <option value="4 5/8">4 5/8</option> </select></td> <td><select name="tube_bend"> <option value="*">*</option> <option value="45">45°</option> <option value="70">70°</option> <option value="90">90°</option> </select></td> <td><select name="end_style"> <option value="*">*</option> <option value="THREADED">Threaded</option> <option value="SMOOTH">Smooth</option> </select></td> Advanced Search Results (modified with code from this thread): http://www.seocorp.com/example_advanced_search_result.htm Here is the actual page: http://seocorp.com/osctesting/product_idle.php I hope somebody out there can help.
Guest Posted February 7, 2006 Posted February 7, 2006 I fixed my problem and now I have another one. After playing around with the code I started getting "There is no product that matches the search criteria". Everything is working however "*" is not a wildcard in the extra field search query. What can I use as a wildcard "everything" character, or how can I make "*" into a wildcard.
Guest Posted February 7, 2006 Posted February 7, 2006 I fixed my problem and now I have another one. After playing around with the code I started getting "There is no product that matches the search criteria". Everything is working however "*" is not a wildcard in the extra field search query. What can I use as a wildcard "everything" character, or how can I make "*" into a wildcard. Sorry for posting again, but I figured out that not using any value is a wildcard. I am using: <option value="">Search All<option>
Recommended Posts
Archived
This topic is now archived and is closed to further replies.