I have a search function searching different criteria but I want to add a table to be searched.
The sql statement is:
$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 ";
I need to add to the search:
select catname from categories
Update: The table structures
categories: id, catname, par_id
image_to_categories: id, imgid, catid
Is that the query you were searching for? I have displayed it in a more readable way.
$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
";
I have added a join to the categories table at the end, and displayed the category at the top.
I hope this helps.
Philippe
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.