Jump to content

COUNT when using FULL TEXT search


AdRock

Recommended Posts

This is my code I have for a search form and it works perfectly.  The problem is I don't know if i can add COUNT to the query to get the number of records that match that condition

 

if (isset($address)) {
        $sql = "SELECT id, userid, seats_available, start_street, start_postcode, 
    end_street, end_postcode, TIME_FORMAT(depart_time,'%H:%i') as depart, 
    MATCH(start_street, start_postcode, end_street, end_postcode) AGAINST('$address*' IN BOOLEAN MODE)
    as score FROM carshare WHERE MATCH(start_street, start_postcode, end_street, end_postcode) 
    AGAINST('$address*' IN BOOLEAN MODE) ";
    }
    else {
    	$sql = "SELECT id, userid, seats_available, start_street, start_postcode, 
end_street, end_postcode, TIME_FORMAT(depart_time,'%H:%i') as depart FROM carshare WHERE 1=1 ";
    }

    if (isset($seats)) {
    	$sql .= "AND seats_available = '$seats' ";
    }
    if (isset($departure)) {
    	$sql .= "AND depart_time = '$departure' ";
    }

    if (isset($address)) {
    	$sql .= "ORDER BY score, $order ASC";
     }
    else {
    	$sql .=" ORDER BY $order ASC";
    }

 

I need to count the number of records so i can paginate the results.  Is it possible to count the number of records using something like

SELECT COUNT (*) , MATCH(start_street, start_postcode, end_street, end_postcode) AGAINST('$address*' IN BOOLEAN MODE) as score FROM carshare WHERE MATCH(start_street, start_postcode, end_street, end_postcode) AGAINST('$address*' IN BOOLEAN MODE)

Link to comment
https://forums.phpfreaks.com/topic/98399-count-when-using-full-text-search/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.