Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3660540
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:13:02+00:00 2026-05-19T01:13:02+00:00

I could use some help to make this search return results in certain situations.

  • 0

I could use some help to make this search return results in certain situations. The user has 2 fields to fill in and I would like to be able to leave either blank or fill in both. The fields are vehicle and keywords. The vehicle field is meant to allow searching based on the make, model, VIN, truck number (often is 2 – 3 digits or a letter prefix followed by 2 digits), and a few other fields that belong to the truck table. The keywords are meant to search most fields in the maintenance and maintenance_parts tables (things like the description of the work, parts name, parts number). Currently leaving the keywords field blank returns no results even when the vehicle field has valid results of its own.

"SELECT M.maintenance_id, M.some_id, M.type_code, M.service_date, M.mileage, M.mg_id, M.mg_type, M.comments, M.work_done,
                MATCH( M.comments, M.work_done) AGAINST( '$keywords' ) +
                MATCH( P.part_num, P.part_desc, P.part_ref) AGAINST( '$keywords' ) +
                MATCH( T.truck_number, T.make, T.model, T.engine, T.vin_number, T.transmission_number, T.comments) AGAINST( '$vehicle' )
                AS score
            FROM maintenance M, maintenance_parts P, truck T
            WHERE M.maintenance_id = P.maintenance_id
            AND M.some_id = T.truck_id
            AND M.type_code = 'truck'
            AND (MATCH( T.truck_number, T.make, T.model, T.engine, T.vin_number, T.transmission_number, T.comments) AGAINST( '$vehicle' )
            OR T.truck_number LIKE '%$vehicle%')
            AND MATCH( P.part_num, P.part_desc, P.part_ref) AGAINST( '$keywords' )
            AND MATCH( M.comments, M.work_done) AGAINST( '$keywords' )
            AND M.status = 'A' GROUP BY maintenance_id ORDER BY score DESC LIMIT 0, $limit";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:13:02+00:00Added an answer on May 19, 2026 at 1:13 am

    You need to change some of your ANDs to ORs and then parenthesize the ORs.

    Right now you require one of the $vehicle MATCHes and also both of the $keyword matches. Instead, I think you want to require any one of the $vehicle or $keyword matches.

    Also, I think that you can combine the $keyword matches into a single MATCH call, can’t you? And I think the LIKE check against T.truck_number is redundant given the MATCH that includes that column. In which case you could write that section of the SQL as:

     AND (MATCH( T.truck_number, T.make, T.model, T.engine, T.vin_number,
          T.transmission_number, T.comments) AGAINST( '$vehicle' )
         OR MATCH( P.part_num, P.part_desc, P.part_ref,M.comments, M.work_done) 
         AGAINST( '$keywords' ))
    

    And I include the obligatory comment about protecting yourself against SQL injection by escaping the dynamic SQL you create.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I could use some help writing a regular expression. In my Django application, users
I could use some help creating an XSL template that will take a string
I am getting the following error and could use some help resolving it. Anyone
We're having a small issue and could use some help - we have the
I have a piece of code here that i really could use some help
This seems to be an overlooked area that could really use some insight. What
I'm just starting to learn T-SQL and could use some help in understanding what's
I made a big oops, and could use some help undoing it. We have
I could really use some help with a Python regular expression problem. You'd expect
I've inherited a rather large application that really could use some cleanup. There is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.