Hey. I am attempting to conbine database searching with pagination but am having problems. The function I have writen looks like this
function searchDB($condition, $value, $page, $per_page)
{
$condition = htmlentities(trim(mysql_real_escape_string($condition)));
$value = htmlentities(trim(mysql_real_escape_string($value)));
$keywords = preg_split("#/[\s]+/#", $value);
$keyword_where = "AND `{$condition}` LIKE '%". implode("%' OR `{$condition}` LIKE '%", $keywords). "%'";
$perpage = (int)$page;
$startpage = (int)($page - 1) * $page;
$results = array();
$query = mysql_query("SELECT `dvdid`, `title`, `genre`,`rating`,`releaseyear`,`dvdtype`,`dateadded`,`disctype` FROM `audio_described_dvd` WHERE `approved` = 1 {$keyword_where} LIMIT {$startpage}, {$perpage}");
while($row = mysql_fetch_assoc($query))
{
$results[] = $row;
}
return $results;
When I try and execute this in my script by doing
$page = $_GET["page"];
if(empty($page))
{
$page = 1;
}
$searchresults = searchDB($_POST["searchby"], $_POST["searchterm"], $page, 5);
it always returns an empty array. I'm not sure what the problem is