我需要从 sub where mainid = $cccc as iiid 中选择 id,然后从 cat = iiid 的广告中选择
并从ads order by id desc limit 10中选择订单
$cccc=intval($_GET['cat']);
$DB = new DB;
$seleddcddddtMainwork ="select id from sub where mainid='$cccc' as iiid from ads where cat='$idididid' order by id desc limit 10 ";
我尝试了很多代码,但它不适用于我。
我试过了:
select sub.mainid='$cccc' as idididid from ads where cat='$idididid' order by id desc limit 10
但我需要从 sub where mainid=cccc 和 ahter 获取 id,从 cat = that id 的广告中选择
CREATE TABLE IF NOT EXISTS `ads` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`userid` int(255) NOT NULL,
`title` varchar(255) NOT NULL,
`photo` varchar(255) NOT NULL,
`message` varchar(255) NOT NULL,
`price` int(255) NOT NULL,
`contery` varchar(255) NOT NULL,
`mobile` varchar(255) NOT NULL,
`showmobile` int(255) NOT NULL,
`showj` int(255) NOT NULL DEFAULT '0',
`youtuube` varchar(255) NOT NULL,
`cat` int(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `photo` (`photo`),
KEY `title` (`title`),
KEY `message` (`message`),
KEY `price` (`price`),
KEY `contery` (`contery`),
KEY `mobile` (`mobile`),
KEY `showmobile` (`showmobile`),
KEY `show` (`showj`),
KEY `youtuube` (`youtuube`),
KEY `userid` (`userid`),
KEY `cat` (`cat`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
CREATE TABLE IF NOT EXISTS `sub` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`mainid` int(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `name` (`name`),
KEY `mainid` (`mainid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=126 ;
我最后一次尝试是:
select id from sub.mainid='$cccc' as idididid from ads where cat='idididid' order by id desc limit 10
也没有工作。
我只有一个值$cccc=intval($_GET['cat']);
,我需要从 sub where mainid=$cccc as iit 中选择 id 并从 cat=iit 的广告中选择
另一件事
SELECT sub.id, sub.mainid
FROM sub
WHERE sub.mainid = '2'
和
此 sub.id 的结果 来自 cat = sub.id 的广告的结果