我有搜索功能搜索不同的条件,但我想添加一个待搜索的表。
sql语句是:
$sql_main = " select distinct s.prefix, istore.* from image_store istore inner join
image_size isz on
istore.id = isz.imgid inner join size s on isz.isize = s.id
inner join image_to_categories ic on istore.id = ic.imgid
where s.id = 1 and istore.istatus = 1 ";
我需要添加到搜索中:
从类别中选择catname
Update: The table structures
categories: id, catname, par_id
image_to_categories: id, imgid, catid
答案 0 :(得分:0)
这是您要搜索的查询吗?我以更易读的方式展示了它。
$sql_main = "
select distinct
s.prefix, istore.*, c.catname
from image_store istore
inner join image_size isz on
istore.id = isz.imgid
inner join size s
on isz.isize = s.id
inner join image_to_categories ic
on istore.id = ic.imgid
inner join categories c
on ic.catid = c.id
where s.id = 1 and istore.istatus = 1
";
我最后在类别表中添加了一个联接,并在顶部显示了该类别。
我希望这会有所帮助。
菲利普