Zen Follower
- Join Date:
- Jun 2005
- Posts:
- 119
- Plugin Contributions:
- 0
Adding LIVE ajax searching to search box
Hi, i am trying to add live ajax searching to the search box... i have succeeded in doing it without using zens functions. but, then my output on certain character rendering doesnt work. so i would like to use the built in zen functionality since it is displaying these characters correctly in other parts of the site.
some background...
i am using scriptaculous / prototype for the js library. this is loaded and functioning. in my search form i added:
$content .= '<div id="autocomplete_choices" class="autocomplete"></div>
<script>
new Ajax.Autocompleter("autocomplete","autocomplete_choices","search/ajaxsearch.php",{paramName: "search"});
</script>';
after the input tag.
i loaded the js files into template/mytemplate/jscript and put references in my header.
the param above search/ajaxsearch.php calls the query on the database. following is the code: the first set commented is the code that works (but returns weird characters on letters with accents) the second code block doesnt return anything on the query.
<?php /* mysql_connect('localhost', 'user', 'password'); mysql_select_db("mydatabasename"); if(!isset($_REQUEST["search"])) exit; $search=mysql_real_escape_string(trim($_REQUEST["search"])); $result = mysql_query("SELECT products_name, products_description.products_id, products.products_id, products_status FROM products_description, products WHERE products_description.products_id = products.products_id AND products_status=1 AND products_name LIKE '%$search%';"); if(mysql_num_rows($result)) { echo "<ul>"; while($r=mysql_fetch_assoc($result)) { $title = $r["products_name"]; echo "<li>$title</li>"; } echo "</ul>"; } */ ?>//////NEW BLOCK HERE///////
<?php require('includes/application_top.php'); $content = ''; if(!isset($_REQUEST["search"])) exit; $search=mysql_real_escape_string(trim($_REQUEST["search"])); $product_query = mysql_query("SELECT a.products_id, b.products_id, b.products_name FROM products a, products_description b where a.products_id = b.products_id order by b.products_name AND products_name LIKE '%$search%';"); $product_result = $db->Execute($product_query); $content .= "<ul>"; while (!$product_result->EOF) { $content .= '<li>'. $product_result->fields['products_name'] . '</li>'; $product_result->MoveNext(); }; $content .= "</ul>"; ?> <?php echo $content; ?>any help would be really really appreciated. i have gotten really far on this and i think a lot of people would like this adaptation. oh and this ajaxsearch.php file is in a subfolder search from the root. not sure if that is the issue or not...
Minnie