Ini adalah contoh cepat. Saya tidak tahu jenis data apa yang dikembalikan JRequest::getVar (selalu berupa string, atau tipe campuran?) tetapi ini akan memulai Anda. Pastikan untuk menggunakan metode pelolosan mana pun yang berlaku dalam loop foreach:
if ($post) {
$criteria = array();
//get all search variables
$criteria['type'] = JRequest::getVar('type');
$criteria['classifications'] = JRequest::getVar('classifications', array(0), 'post', 'array');
$criteria['rating'] = JRequest::getVar('rating');
//if there are some criteria, make an array of fieldName=>Value maps
if(!empty($criteria)) {
$where = array();
foreach($criteria as $k => $v) {
//IMPORTANT!!
//$v is the value of the field, needs to be quoted correctly!!
$where[] = "$k = '$v'";
}
}
//create search string
$query = "SELECT * FROM #__db_clients";
if($where) {
$query .= " where " . join(' AND ', $where);
}
} else {
echo 'There has been an error, please try again.';
};