I have two queries pulling information to create a page but I'd really like to get this down to one query - I think it's possible but I'm not sure (meaning I have been unsuccessful so far):
// query one
$rs = $db->fetchRecord(
"SELECT *
FROM t_$page[p_table],t_templates
WHERE id='$page[p_page_id]'
AND t_$page[p_table].templid=t_templates.templid
");
// templ_plug comes in the form of 2,5,8,34,21
$plugins = explode(',',$rs['templ_plug']);
// query two
$plug = $db->fetchArray("
SELECT incl_code FROM t_incl
WHERE (incl_type = '1' AND (incl_id IN (" .implode(',',$plugins). ")))
OR ((incl_type='1') AND (incl_sys = '1'))
ORDER BY incl_sys ASC");
//
These, as they are, work great. Now, taking this further...I'm confused about which kind of JOIN could pull this off. Additionally, because I do need to the sort the order of the second query I wonder if this throws everything into a mess. This is where I am sort of but it's not pulling up anything even close to what it should...
$rs = $db->fetchRecord(
"SELECT incl_code
FROM t_$page[p_table],t_templates
INNER JOIN t_incl
WHERE id='$page[p_page_id]'
AND t_$page[p_table].templid=t_templates.templid
AND ((incl_type = '1' AND (incl_id IN (templ_plug)))
OR ((incl_type='1') AND (incl_sys = '1')))
ORDER BY incl_sys ASC
");
Helllllp. 😉