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 8815795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:27:56+00:00 2026-06-14T04:27:56+00:00

I’m new to php and mysql so I need some help with my query.

  • 0

I’m new to php and mysql so I need some help with my query. This is my sql query

SELECT * FROM table1 WHERE (Name LIKE '%$keyword%' OR ZipCode LIKE '%$keyword%') AND Category LIKE '$category' AND Country LIKE '$country' LIMIT $start, $limit

Now what I want to do exaclty is

  1. This query should search column names with Name or ZipCode using a text field with the name keyword. That is either keyword matches the Name column or the ZipCode.
  2. The query should also work if no keyword is entered and only a country is selected from a dropdown.
  3. The query should also work if no keyword or country is input and only a category is selected from a dropdown.

In more simple words if either of the things keyword, country or category is selected the search should display results accordingly. Moreover it should also work if all the fields are input. I managed to do half of it but sometimes it gives me wrong results. Please help.

  • 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-14T04:27:57+00:00Added an answer on June 14, 2026 at 4:27 am

    You can check which of the fields are set and make query accordingly at runtime. something like this you can do:

    $query = "";
    $keyword = $_REQUEST['keyword'];
    $country = $_REQUEST['country'];
    $category = $_REQUEST['category'];
    if(isset($keyword)){//if keyword set goes here
       $query = "SELECT * FROM table1 WHERE Name LIKE '%$keyword%' OR ZipCode LIKE '%$keyword%' OR country LIKE '%$keyword%'";
       if(isset($category)){
         $query .= "AND category LIKE '$category'";
       }
       if(isset($country)){
         $query . = "AND country LIKE '$country'"
       }
    }else if (isset($category)){ //if keyword not set but category set then goes here
      $query = "SELECT * FROM table1 WHERE category LIKE '$category'";
      if(isset($country)){
        $query . = "AND country LIKE '$country'";
      }
    }else if(isset($country)){//if only country set goes here
      $query = "SELECT * FROM table1 WHERE country LIKE '$country'"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string
Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.