Answer the question
In order to leave comments, you need to log in
Exact MySQL search. How to implement?
I have the following database table
--
-- `board` table structure
--
DROP TABLE IF EXISTS `board`;
CREATE TABLE IF NOT EXISTS `board` (
`id` int(11) auto_increment,
`user_id` int(11) NOT NULL,
`cat_id` varchar(250) NOT NULL,
`name` varchar(250) NOT NULL,
`translate ` varchar(250) NOT NULL,
`text` varchar(15000) NOT NULL,
`email` varchar(64) NOT NULL,
`phone` varchar(20) NOT NULL,
`person` varchar(250) NOT NULL,
`region_id ` int(11) NOT NULL,
`city_id` int(11) NOT NULL,
`address` varchar(500) NOT NULL,
`price` varchar(11) NOT NULL,
`time` int(11) NOT NULL,
`timeupdate` int(11) NOT NULL,
`timesrok` int(11) NOT NULL,
`status` enum ('1','2') NOT NULL default '2',
`activation` enum ('1','2') NOT NULL default '1',
`torg` enum ('0','1') NOT NULL default '0',
`free` enum ('0',' 1') NOT NULL default '0',
`vip` enum ('0','1') NOT NULL default '0',
`viptime` int(11) NOT NULL,
`select` enum('0',' 1') NOT NULL DEFAULT '0',
`selecttime` int(11) NOT NULL,
`confirm` enum('0','1') NOT NULL DEFAULT '0',
`sendemail` enum('0','1') NOT NULL DEFAULT '0',
`type` enum('1','2') NOT NULL default '1',
`del` enum('0','1') NOT NULL DEFAULT '0',
`file` enum('0','1') NOT NULL DEFAULT '0',
`views` int(11) NOT NULL default '0',
`url` varchar(2000) NOT NULL,
`lat` varchar(11 ) NOT NULL,
`lng` varchar(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
FULLTEXT `cat_id` (`cat_id`),
KEY `region_id` (`region_id` ),
KEY `city_id` (`city_id`),
FULLTEXT `s1` (`name`, `text`, `price`),
KEY `status` (`status`),
KEY `activation` (`activation`),
KEY `del` (`del`),
KEY `file` (`file`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
Category IDs are written in cat_id separated by commas (perhaps this is not the best approach). You need to count the number of ads in each category
So
SELECT `category`.*, (SELECT COUNT(1) FROM `board` WHERE `board`.`cat_id` LIKE CONCAT('%', `category`.`id`, '%') AND `status`='1' AND `activation`='1' AND `del`='0' И ТУТ МОЖЕТ БЫТЬ ЕЩЕ ДОП. ФИЛЬТРОВКА) AS `count` FROM `category` WHERE `refid`='1' ORDER BY `realid` ASC
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question