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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:07:02+00:00 2026-05-23T22:07:02+00:00

I have my php/mysql SELECT code which doesn’t return a result to what I

  • 0

I have my php/mysql SELECT code which doesn’t return a result to what I have expected after execution of the code.
Code: [Select]

$sql="SELECT *FROM advert 
       WHERE ad_Type = '%{$service}%' AND
            ad_Street_No like '%{$location}%' OR
            ad_Street_Name like '%{$location}%' OR
            ad_Suburb like '%{$location}%' OR
            ad_Postcode like '%{$location}%' OR
            ad_State like '%{$location}%'";

The user will search on location and the type of service available using parameters like street name,suburb, postcode and/or state in one textfield and then select a type of service from a dropdown menu. So for example : “Select records from table ‘advert’ where type of service = ‘e.g. hauling,digging,’ located at e.g. Cardiff NSW”. ” something like that.

I have 2 records right now on my database :
1. Service: Hauling, Location: Cardiff NSW
2. Service: Digging , Location: Cardiff NSW

Now the problem is:

you search for “Hauling” service in “Cardiff” , will return 2 records (#1 and #2).
you search for “Digging” service in “Cardiff”, will return 2 records (#1 and #2).
you search for either of the services in ” Cardiff NSW”, will return 0 results.

I got no idea on how to fix this. Please help me guys. Thank you in advance. 🙁 🙁 🙁

Best regards

  • 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-23T22:07:02+00:00Added an answer on May 23, 2026 at 10:07 pm

    First off, you need some brackets:

    $sql="SELECT *FROM advert 
           WHERE ad_Type like '%{$service}%' AND
               ( ad_Street_No like '%{$location}%' OR
                 ad_Street_Name like '%{$location}%' OR
                 ad_Suburb like '%{$location}%' OR
                 ad_Postcode like '%{$location}%' OR
                 ad_State like '%{$location}%'" );
    

    That will fix your first case. But you also need to think about exactly what it is you’re providing : for instance if you only provide a town then you don’t want to include ad_Type in your query at all.

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

Sidebar

Related Questions

I have the following PHP/MySQL code: function executeMultirowQuery($query) { $result = mysql_query($query); $table =
I have a legacy PHP/MySQL app that calls mysql_connect(). Tons of existing downstream code
I am used to developing in PHP/MySQL and have no experience developing with SQL
I have a PHP web application which uses a MySQL database for object tagging,
I have a problem with mysql connection. I have a php script which upload
here's my php MySQL syntax $query_cruises = SELECT * FROM cruises, fares WHERE cruises.id
I have a PHP search suggestion script which uses a MySQL database as its'
I have the code below which links to a page called deletepage.php which is
I have this php code, with which I am trying to generate a popup
I have a page which does a SQL query via PHP and generates a

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.