PHP MySql search combining results from two columns

  Kiến thức lập trình

I am creating an aircraft listing site and im trying to build in a search feature. Below is the MySql search query that is working well. However; if I search “cessna” I get all the Cessna’s that come from listings_aircraft.make and if I search “172” I get all the 172s that come from listings_aircraft.model. But if I search “Cessna 172” I get zero results. How would I modify my query to look for both Cessna and 172 combining the listings_aircraft.make and listings_aircraft.model search together if there is a match in both? Thanks in advance.

  $query = "SELECT listing_control.*, 
    listings_aircraft.year, listings_aircraft.make, listings_aircraft.model, 
    listings_aircraft.price, listings_aircraft.callforprice, 
    listings_aircraft.about, listings_aircraft.aircraft_location
    FROM listing_control
    LEFT JOIN listings_aircraft
    ON listings_aircraft.id = listing_control.listing_id 
    WHERE listings_aircraft.make LIKE '%{$search}%'
    OR listings_aircraft.model LIKE '%{$search}%'
    OR listings_aircraft.about LIKE '%{$search}%' 
    OR listings_aircraft.registration LIKE '%{$search}%' 
    AND NOT listing_control.listing_status = 'draft' 
    AND NOT listing_control.listing_status = 'sold'
    AND NOT listing_control.listing_status = 'expired'
    ORDER BY listing_control.date_created DESC";

LEAVE A COMMENT