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

  • Home
  • SEARCH
  • 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 8421993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:18:34+00:00 2026-06-10T03:18:34+00:00

I have some search functionality which allows a user to either select a name

  • 0

I have some search functionality which allows a user to either select a name from a drop down list or type a persons name or part of it (wildcard functionality) into a search field.

The problem I am having is that if the drop down option is used then the search field won’t be and vice versa.

I have tried some SQL as follows (please note the variables represent data sent in via a form):

SELECT id, name, age FROM player
    WHERE player.id = '$id'
        OR player.name LIKE '%$text%'

When the above is used the wildcard functionality works fine.

However if you select a player from the drop down then it returns all players. This is because the value for $text is nothing (empty) and LIKE ‘%%’ means select everything and hence it selects all names.

I then tried the following:

SELECT id, name, age FROM player
    WHERE player.id = '$id'
        AND player.name LIKE '%$text%'

Now the drop down functionality works as expected but wild card searches do not work. This is because I assume that AND requires both statements to be true and because $id is nothing (empty) when just a wildcard entry is specified, the condition is never true.

Can anyone help me with some sql to ensure that both the dropdown and the wildcard search work in isolation of each other?

Thanks for your time and help in advance.

  • 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-06-10T03:18:36+00:00Added an answer on June 10, 2026 at 3:18 am
    $params = ''
    
    if($id !== ''){
      $params = "player.id = '$id'";
    } else if($text !== ''){
      $params = "player.name LIKE '%$text%'";
    }
    
    $sql = "SELECT id,name,age FROM player WHERE {$params}";
    
    mysql_query($sql);  //if using mysql_ 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some search functionality that can return tens of thousands of results from
I have some XML which I'm trying to search: <debts> <section id=24 description=YYYYY> <section
We have some code which produces an RTF document from a RTF template. It
I have some code that starts a background process for search in my WPF
I have a simple script that does some search and replace. This is basically
I have found some posts related to search on XML but those were not
I have a folder full of files and I want to search some string
I have already search for some time over the net on how to create
I have a search setup inside a div but for some reason cannot get
I have a search page and want to add some filters to it, my

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.