我的问题是,由于我将 SWITCH 函数添加到代码中以使用 cat_id 进行查询,因此代码无法再将查询条件传递给 URL 以进行分页。cat_id 是一个 categoryID,它作为外键保存在子表中。
如果您可以提供帮助,这是我的代码:
$criteria = array('ctitle', 'csubject', 'creference', 'cat_id', 'cmaterial', 'ctechnic', 'cartist', 'csource', 'cposture', 'stolen');
$likes = "";
$url_criteria = '';
foreach ( $criteria AS $criterion ) {
if ( ! empty($_POST[$criterion]) ) {
$value = ($_POST[$criterion]);
$likes .= " AND `$criterion` LIKE '%$value%'";
switch ($criterion) {
case 'cat_id':
$likes .= " AND `$criterion`='$value'";
break;
default:
$likes .= " AND `$criterion` LIKE '%$value%'";
break;
$url_criteria .= '&'.$criterion.'='.htmlentities($_POST[$criterion]);
}
} elseif ( ! empty($_GET[$criterion]) ) {
$value = mysql_real_escape_string($_GET[$criterion]);
$likes .= " AND `$criterion` LIKE '%$value%'";
switch ($criterion) {
case 'cat_id':
$likes .= " AND `$criterion`='$value'";
break;
default:
$likes .= " AND `$criterion` LIKE '%$value%'";
break;
$url_criteria .= '&'.$criterion.'='.htmlentities($_GET[$criterion]);
} //var_dump($likes);
}
}
$sql = "SELECT * FROM collections WHERE c_id>0" . $likes . " ORDER BY c_id ASC";