我正在获取表单数据,并使用它分别获取它们,然后合并。我当前的查询是这样:
$design_code = $_POST['design_num'];
$design_code .= ':'.$db->single('SELECT code FROM '. table_brands .' WHERE id=?', [$_POST['brand']]);
$design_code .= ':'.$db->single('SELECT code FROM '. table_types .' WHERE id=?', [$_POST['type']]);
$design_code .= ':'.$db->single('SELECT code FROM '. table_quality .' WHERE id=?', [$_POST['quality']]);
$design_code .= ':'.$db->single('SELECT code FROM '. table_sizes .' WHERE id=?', [$_POST['size']]);
所有POST数据都是独立的,因此无法加入。将它们合并为一个合适的替换查询是什么。
PS:$db->single()
基本发送一个字段值。
答案 0 :(得分:0)
尝试
select (select code FROM table1 where id = 1 ) as code1, (select code FROM table2 where id = 1 ) as code2, table3.code3 FROM table3 where id = 1
结果将显示在一行中。
使用UNION查询,结果将超过一行。
编辑
根据您的最新评论“请检查:pastebin.com/qGmp8ZKq”更新查询
select (select code FROM brand where id = 2 ) as code1, type.code FROM type where id = 6