thinkphp提供了join方法来实现关联查询,但是很不好用,还是用原生的方便,所以推荐大家用query方法:
复制代码 代码如下:
$Model = new Model();
$sql = "SELECT a.id, a.attr_name, a.attr_input_type, a.attr_type, a.attr_values, v.attr_value, v.attr_price ".
"FROM hh_typeattr AS a ".
"LEFT JOIN hh_siteattr AS v ".
"ON v.attr_id = a.id AND v.site_id = '$site_id' ".
"WHERE a.type_id = " . intval($type_id) ." OR a.type_id = 0 ".
"ORDER BY a.listorder, a.attr_type, a.id, v.attr_price, v.id";
$row = $Model->query($sql);