Witam
Mam problem, muszę zmodyfikować to zapytanie:
<?php
$select = $db->select()->from(array('t' => DB_PREFIX
. 'prod_translations'), array('options', 'product_name', 'description'))->join(array('p' => DB_PREFIX
. 'products'), 'p.product_id = t.pid', array('product_id', 'category_id', 'gfx', 'vat', 'promo', 'weight', 'in_stock', 'price', 'actual_price' =>
'IF(s.special_price, s.special_price, p.price)'))->joinLeft(array('g' => DB_PREFIX
. 'gfx'), 't.pid = g.prod_id AND g.main_gfx = 1', array('unic_name'))-> joinLeft
(array('s' => DB_PREFIX
. 'special_offers'), ' AND s.date_to >= ' . strtotime(date("Y-m-d")), array('special_price'))->where('t.lang = ?', $session->lang)->where('t.active = 1')->limit($krok, $page * $krok);
?>
tak żeby dodać do tego jest wyciąganie nazwy producenta z tabeli manufactures, która wygląda tak:
CREATE TABLE `manufacturers` (
`producent_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
`info` varchar(99) NOT NULL DEFAULT '',
`web` varchar(255) NOT NULL DEFAULT '',
`gfx` varchar(30) NOT NULL DEFAULT '',
`isdefault` tinyint(1) NOT NULL,
PRIMARY KEY (`producent_id`),
KEY `name` (`name`),
KEY `isdefault` (`isdefault`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1087 ;
i dodatkowo pogrupować wyniki po nazwie producenta (kolumna name w tabeli manufactures).
Oto pozostałe tabele:
CREATE TABLE `prod_translations` (
`id_transl` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`pid` int(11) NOT NULL DEFAULT '0',
`product_name` varchar(255) character SET utf8 collate utf8_polish_ci NOT NULL,
`description` mediumtext character SET utf8 collate utf8_polish_ci NOT NULL,
`params` mediumtext NOT NULL,
`jm` varchar(32) NOT NULL DEFAULT '',
`options` mediumtext NOT NULL,
`active` tinyint(1) NOT NULL,
`lang` char(3) NOT NULL DEFAULT '',
`isdefault` tinyint(1) NOT NULL,
PRIMARY KEY (`id_transl`),
UNIQUE KEY `pid` (`pid`,`lang`),
KEY `lang_active` (`active`,`lang`),
KEY `product_name_2` (`product_name`),
KEY `pid_2` (`pid`),
KEY `product_name_3` (`product_name`,`lang`),
KEY `lang` (`lang`),
KEY `isdefault` (`isdefault`),
FULLTEXT KEY `product_name` (`product_name`),
FULLTEXT KEY `search` (`product_name`,`description`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6271 ;
CREATE TABLE `products` (
`product_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`category_id` int(11) UNSIGNED NOT NULL DEFAULT '0',
`producer_id` int(11) UNSIGNED DEFAULT NULL,
`rate` float DEFAULT NULL,
`votes` int(6) DEFAULT NULL,
`vat` varchar(8) NOT NULL DEFAULT '0',
`in_stock` int(11) NOT NULL DEFAULT '1',
`gfx` varchar(99) DEFAULT NULL,
`gfx_small` varchar(30) DEFAULT NULL,
`gfx_enlarge` varchar(30) DEFAULT NULL,
`file` varchar(255) DEFAULT NULL,
`add_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`edit_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`price` decimal(10,2) NOT NULL DEFAULT '0.00',
`promo` char(1) NOT NULL DEFAULT '',
`warranty` int(11) NOT NULL DEFAULT '0',
`weight` varchar(12) NOT NULL DEFAULT '',
`views` int(7) NOT NULL DEFAULT '0',
`category2` int(11) UNSIGNED NOT NULL DEFAULT '0',
`category3` int(11) UNSIGNED NOT NULL DEFAULT '0',
`sort` int(11) NOT NULL DEFAULT '0',
`main_page` tinyint(1) NOT NULL,
`main_page_sort` int(11) NOT NULL DEFAULT '0',
`products_related` mediumtext NOT NULL,
`other_price` float NOT NULL DEFAULT '0',
`product_code` varchar(255) NOT NULL DEFAULT '',
`pkwiu` varchar(255) DEFAULT NULL,
PRIMARY KEY (`product_id`),
UNIQUE KEY `product_code_2` (`product_code`),
KEY `producer_id` (`producer_id`),
KEY `add_date` (`add_date`),
KEY `sort` (`sort`),
KEY `categories` (`category_id`,`category2`,`category3`),
KEY `main_page` (`main_page`),
KEY `main_page_sort` (`main_page_sort`),
KEY `price` (`price`),
KEY `in_stock` (`in_stock`),
KEY `promo` (`promo`),
KEY `category2` (`category2`),
KEY `category3` (`category3`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 PACK_KEYS=0 AUTO_INCREMENT=6271 ;
CREATE TABLE `gfx` (
`gfx_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`prod_id` int(11) UNSIGNED NOT NULL DEFAULT '0',
`main_gfx` int(1) NOT NULL DEFAULT '0',
`name` varchar(60) NOT NULL DEFAULT '',
`unic_name` varchar(60) NOT NULL DEFAULT '',
`gfx_sort` int(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`gfx_id`),
UNIQUE KEY `unic_name` (`unic_name`),
KEY `prod_id` (`prod_id`),
KEY `main_gfx` (`main_gfx`),
KEY `gfx_sort` (`gfx_sort`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE `special_offers` (
`promo_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`pid` int(11) UNSIGNED NOT NULL DEFAULT '0',
`special_price` decimal(10,2) NOT NULL DEFAULT '0.00',
`date_from` int(11) DEFAULT NULL,
`date_to` int(11) DEFAULT NULL,
`start_page` tinyint(1) NOT NULL,
PRIMARY KEY (`promo_id`),
KEY `pid` (`pid`),
KEY `date_from` (`date_from`,`date_to`),
KEY `start_page` (`start_page`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 PACK_KEYS=0 AUTO_INCREMENT=1 ;
ktoś jest w stanie to zrobić, bo sam sobie jakoś nie mogę z tym poradzić a jest mi to potrzebne koniecznie.
Pozdrawiam