0
fI似乎是一個相對簡單的AND/OR子句,它讓我頭疼。使用AND/OR邏輯運算符的SQL查詢
$query = "SELECT stv.name,stc.tmplvarid,stc.contentid,stv.type,stv.display,stv.display_params,stc.value";
$query .= " FROM ".$tb1." stc LEFT JOIN ".$tb2." stv ON stv.id=stc.tmplvarid ";
$query .= " LEFT JOIN $tb_content tb_content ON stc.contentid=tb_content.id ";
$query .= " WHERE stv.name='".$region."' AND stc.contentid IN (".implode($cIDs,",").") ";
$query .= " OR stv.name='".$countries."' AND stc.contentid IN (".implode($cIDs,",").") ";
$query .= " AND tb_content.pub_date >= '$pub_date' ";
$query .= " AND tb_content.published = 1 ";
$query .= " ORDER BY stc.contentid ASC;";
我需要從兩個$region
和$countries
檢索值。但是,它只是返回值$countries
。如果我刪除OR
的行,它將返回值$region
,但它不會同時返回。我做錯了什麼?
謝謝,但它仍然只是返回$國家。如果有幫助,以下是完整的功能:http://pastebin.com/E4CdnQNj – Vecta 2010-11-09 15:51:51