โค้ด: เลือกทั้งหมด
$sql_array = array(
'SELECT' => 'DISTINCT tt.topic_id',
'FROM' => array(
$this->m_topictags => 'tt'
),
'WHERE' => array(),
'LEFT_JOIN' => array(),
'ORDER_BY' => array(),
);
if ($a_search[0]) {
$sql_array['WHERE'] = 'tt.topic_id IN (' . $a_search[0] . ')';
$topic_id_search_tmp = $this->db->sql_build_query('SELECT', $sql_array);
}
if (count($a_search) != 1) {
$sql = 'CREATE TEMPORARY TABLE tmp_topic_id_new ( topic_id_tmp INT NOT NULL );';
$result = $this->db->sql_query($sql);
$sql = 'INSERT INTO tmp_topic_id_new (topic_id_tmp)' . $topic_id_search_tmp;
// echo $sql; exit;
$result = $this->db->sql_query($sql);
$sql_tmp_select = 'SELECT * FROM tmp_topic_id_new';
// ---- debug ว่ามีเลข topic เข้าตารางหรือยัง
// $result = $this->db->sql_query($sql_tmp_select);
//
// while ($row = $this->db->sql_fetchrow($result)) {
// $topic_id_tmp[] = $row['topic_id_tmp'];
// }
// print_r($topic_id_tmp);
// echo '<hr>';
//---- debug ว่ามีเลข topic เข้าตารางหรือยัง
$and_tmpsearch = ' AND tt.topic_id IN (' . $sql_tmp_select . ')';
foreach ($a_search as $value) {
$a_search_and_tmp[] = ' tt.topic_id IN (' . $value . $and_tmpsearch . ')';
}
// print_r($a_search_and_tmp); echo '<hr>';
//$a_search[] = 'tt.topic_id IN (' . $where_nametag . ')';
$sql_array['WHERE'] = implode(' AND', $a_search_and_tmp);
}
$topic_id_search = $this->db->sql_build_query('SELECT', $sql_array);