Sign in to follow this  
KoVaLsKy

1. Как добавить картинку товара в AJAX поиск

Recommended Posts

KoVaLsKy


<?php
define("AJAX_QUICKSEARCH_RESULT", 'text'); // dropdown or text
define("AJAX_QUICKSEARCH_DROPDOWN_SIZE", 5);
define("AJAX_QUICKSEARCH_LIMIT", 15);
$q = addslashes(preg_replace("%[^0-9a-zA-Zа-яА-Я\s]%iu", "", $_REQUEST['keywords']) );
$out = "";
if(isset($q) && vam_not_null($q)) {
$searchwords = explode(" ",$q);
$nosearchwords = sizeof($searchwords);
foreach($searchwords as $key => $value) {
if ($value == '')
unset($searchwords[$key]);
}
$searchwords = array_values($searchwords);
$nosearchwords = sizeof($searchwords);
foreach($searchwords as $key => $value) {
$booltje = '+' . $searchwords[$key] . '*';
$searchwords[$key] = $booltje;
}
$q = implode(" ",$searchwords);
$products_query = vam_db_query("select pd.products_id, pd.products_name, pd.products_keywords, p.products_model, p.products_image
from " . TABLE_PRODUCTS_DESCRIPTION . " pd
inner join " . TABLE_PRODUCTS . " p
on (p.products_id = pd.products_id)
where (match (pd.products_name) against ('" . $q . "' in boolean mode)
or match (p.products_model) against ('" . $q . "' in boolean mode) or match (p.products_ean) against ('" . $q . "' in boolean mode) or match (pd.products_keywords) against ('" . $q . "' in boolean mode)" .
($_REQUEST['search_in_description'] == '1' ? "or match (pd.products_description) against ('" . $q . "' in boolean mode)" : "") . ")
and p.products_status = '1'
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
order by pd.products_name asc
limit " . AJAX_QUICKSEARCH_LIMIT);
if(vam_db_num_rows($products_query)) {
$out .= sprintf(TEXT_AJAX_QUICKSEARCH_TOP, AJAX_QUICKSEARCH_LIMIT) . '<br />';
$dropdown = array();
$out .= '<ul class="ajaxQuickFind">';
while($products = vam_db_fetch_array($products_query)) {
if ($products['products_image']==''){
$image = DIR_WS_INFO_IMAGES.'../noimage.gif';
}else{
$image = DIR_WS_INFO_IMAGES.$products['products_image'];
}
$out .= '<li class="ajaxQuickFind"><a rel=nofollow" href="' . vam_href_link(FILENAME_PRODUCT_INFO, vam_product_link($products['products_id'], $products['products_name']), 'NONSSL', false) . '"><img style="width:60px;" class="ajaximg" src="' . $image . '"/><span>' . $products['products_name'] . '</span></a></li>' . "\n";
$dropdown[] = array('id' => $products['products_id'],
'text' => $products['products_name']);
}
$out .= '</ul>' . "\n";
if(AJAX_QUICKSEARCH_RESULT == 'dropdown') {
$out .= vam_draw_pull_down_menu('AJAX_QUICKSEARCH_pid', $dropdown, '', 'onChange="this.form.submit();" size="' . AJAX_QUICKSEARCH_DROPDOWN_SIZE . '" class="ajaxQuickFind"') . vam_hide_session_id();
}
}
}
echo $out;
?>
[/CODE] вот готовый код, в нем правда еще добавлен поиск по штрихкоду а вот разборка в строчку
[CODE]
$products_query = vam_db_query("select pd.products_id, pd.products_name, pd.products_keywords, p.products_model
добавлен запрос на картинку товара т.е вот

$products_query = vam_db_query("select pd.products_id, pd.products_name, pd.products_keywords, p.products_model, p.products_image
[/code] далее проверяем, есть у товара картинка после
[code]
while($products = vam_db_fetch_array($products_query)) {
вставляем

if ($products['products_image']==''){
$image = DIR_WS_INFO_IMAGES.'../noimage.gif';
}else{
$image = DIR_WS_INFO_IMAGES.$products['products_image'];
}
[/code] в строчку
[code]
$out .= '<li class="ajaxQuickFind"><a rel=nofollow" href="' . vam_href_link(FILENAME_PRODUCT_INFO, vam_product_link($products['products_id'], $products['products_name']), 'NONSSL', false) . '"><span>' . $products['products_name'] . '</span></a></li>' . "\n";
добавлен вывод картинки, т.е вот

$out .= '<li class="ajaxQuickFind"><a rel=nofollow" href="' . vam_href_link(FILENAME_PRODUCT_INFO, vam_product_link($products['products_id'], $products['products_name']), 'NONSSL', false) . '"><img style="width:60px;" class="ajaximg" src="' . $image . '"/><span>' . $products['products_name'] . '</span></a></li>' . "\n";

[/code]

все. осталось стилями оформить по красивее.

Share this post


Link to post
Share on other sites
Bomond

а есть пример как у тебя выглядит?

я делал вот тут похожее))

Share this post


Link to post
Share on other sites
KoVaLsKy

сей час на денвере.

на след неделе выложу сайт в сеть

Share this post


Link to post
Share on other sites
sdi_68

А как-то можно это доработать, чтобы окно с результатами не раздвигала существующий блок, а как-бы накладывалась сверху, как в примере у Bomond (выше).

Share this post


Link to post
Share on other sites
support

Можно конечно, в css стилях для этого блока укажите position: absolute;

По идее, должно помочь.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this