Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Ajax search Suggest - HELP !


luigi_77

Recommended Posts

Hi i'm Luigi from Italy.

If possible give me a help (sorry for my english)

 

I have installed a contribution AJAX Search Suggest. It's OK.

But the search is not good for me.

 

 

Example: if i type "S" in the search box the result is ALL products when CONTAINS this character.

This type of search is not good for me.

 

I need - Example:

if i type "S" in the search box the result should be ALL products when BEGIN with this character.

 

Help me - please.....

Link to comment
Share on other sites

I post my file searchsuggest.php

 

Copyright 2006 Ryan Smith / 345 Technical / 345 Group.

*/

include('includes/application_top.php');

///Make sure that a value was sent.

if (isset($_GET['keywords']) && $_GET['keywords'] != '') {

//Add slashes to any quotes to avoid SQL problems.

$search = addslashes($_GET['keywords']);

//Get every page title for the site.

//$sql = "SELECT pd.products_name, WHERE products.products_status=1 AND products_description.products_name like('%" . tep_db_input('%" . tep_db_input($_GET['keywords']) . "%') LIMIT 15";

//$sql = "select pd.products_name, p.products_id from " . TABLE_PRODUCTS_DESCRIPTION . " pd left join " . TABLE_PRODUCTS . " p on pd.products_id = p.products_id WHERE p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and pd.products_name like('%" . tep_db_input($_GET['keywords']) . "%') LIMIT 15";

$sql = "select pd.products_name, p.products_id from " . TABLE_PRODUCTS_DESCRIPTION . " pd left join " . TABLE_PRODUCTS . " p on pd.products_id = p.products_id WHERE p.products_status = '1' and pd.language_id = '" . (int)$languages_id . "' and pd.products_name like('%" . tep_db_input($_GET['keywords']) . "%') LIMIT 15";

 

/**

* Set XML HTTP Header for ajax response

*/

header('Content-Type: text/xml;');

header('Cache-Control: no-cache;');

echo '<?xml version="1.0" encoding="iso-8859-2" ?>' . "\n";

 

echo '<response>' . "\n";

echo ' <suggestlist>' . "\n";

$product_query = tep_db_query($sql);

while($product_array = tep_db_fetch_array($product_query)) {

//$product_array['products_name'] = htmlentities($product_array['products_name']);

//echo '<a href="' . tep_href_link('product_info.php', 'products_id=' . $product_array['products_id']) . '">' . $product_array['products_name'] . '</a>' . "\n";

echo '<item>' . "\n";

echo ' <name><![CDATA[' . $product_array['products_name'] . ']]></name>' . "\n";

echo ' <url><![CDATA[' . tep_href_link('product_info.php', 'products_id= . $product_array['products_id]) . ']]></url>' . "\n";

echo '</item>' . "\n";

}

}

echo ' </suggestlist>' . "\n";

echo '</response>' . "\n";

 

include('includes/application_bottom.php');

?>

 

I think when the solution is in the RED line... but i'm not sure....

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...