Monday, May 14, 2012

how do you word the query to paginate a fulltext search correctly?

I just started working on a search feature for a small site im creating for a friend, and im having a bit of trouble building the query to page the search results.



the query I've created works perfect minus pagination:



$sql = "SELECT *,

MATCH(title, desc) AGAINST('$keyword') AS score

FROM database

WHERE MATCH(title, desc) AGAINST('$keyword') AND `cat` = '$cat' ";


but then for paging, im use to doing something like:



$query = "SELECT COUNT(*) as num FROM $tableName";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];


so the part where im lost is how can I combine the two? I tried:



$sql = "SELECT COUNT(*),

MATCH(title, desc) AGAINST('$keyword') AS score

FROM database

WHERE MATCH(title, desc) AGAINST('$keyword') AND `cat` = '$cat' ";


im somewhat new to programming so this is probably a stupid question but any help would be greatly appreciated





No comments:

Post a Comment