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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.