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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:32:36+00:00 2026-05-26T15:32:36+00:00

I’m developing a search engine for my web project (PHP/MySQL). User should be able

  • 0

I’m developing a search engine for my web project (PHP/MySQL).
User should be able to find a hotel by certain conditions

  1. Location
  2. Facilities
  3. Languages

tables are as following

  1. tblHotels *hotel_id* PK hotel_name
  2. tblLocations *location_id* PK location_name
  3. tblFacilities *facility_id* PK facility_name
  4. tblLanguages *language_id* PK language_name
  5. tblHotelLocations
    *location_id* FK
    *hotel_id* FK
  6. tblHotelFacilities
    *facility_id* FK
    *hotel_id* FK
  7. tblHotelLanguages
    *language_id* FK
    *hotel_id* FK

For example user wants to search for hotel, located in San Francisco (*location_id*)
with Free Wi-Fi (*facility_id*) and Pool (*facility_id*)
where staff speaks English (*language_id*) and Spanish (*language_id*)

Obviously, user may change search conditions, like adding Breakfast to facilities or German to languages.
In this case, search results should reflect hotels, where all conditions are true.

Or he may not pick any facilities (languages etc), in this case, only hotels with no facilities at all should be returned.

Is it possible to do it with one query? I’m pretty sure it is and somehow connected with INNER JOINs. But i’m just stuck 🙁 Any clue?

Thanks in advance!

UPDATE: DB Schema attached

/*
-- Query: desc tblHotels
-- Date: 2011-11-02 09:37
*/

INSERT INTO `tblhotels` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('hotel_id','int(11)','NO','PRI',NULL,'auto_increment');

INSERT INTO `tblhotels` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('hotel_name','varchar(45)','YES','UNI',NULL,'');


/*
-- Query: desc tblFacilities
-- Date: 2011-11-02 09:37
*/

INSERT INTO `tblfacilities` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('facility_id','int(11)','NO','PRI',NULL,'auto_increment');

INSERT INTO `tblfacilities` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('facility_name','varchar(45)','YES','UNI',NULL,'');

/*
-- Query: desc tblLocations
-- Date: 2011-11-02 09:37
*/

INSERT INTO `tbllocations` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('location_id','int(11)','NO','PRI',NULL,'auto_increment');

INSERT INTO `tbllocations` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('location_name','varchar(45)','YES','UNI',NULL,'');


/*
-- Query: desc tblLanguages
-- Date: 2011-11-02 09:37
*/

INSERT INTO `tbllanguages` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('language_id','int(11)','NO','PRI',NULL,'auto_increment');

INSERT INTO `tbllanguages` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('language_name','varchar(45)','YES','UNI',NULL,'');


/*
-- Query: desc tblHotelFacilities
-- Date: 2011-11-02 09:39
*/

INSERT INTO `tblhotelfacilities` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('tblHotelFacilities_id','int(11)','NO','PRI',NULL,'auto_increment');

INSERT INTO `tblhotelfacilities` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('facility_id','int(11)','YES','',NULL,'');

INSERT INTO `tblhotelfacilities` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('hotel_id','int(11)','YES','',NULL,'');


/*
-- Query: desc tblHotelLocations
-- Date: 2011-11-02 09:39
*/

INSERT INTO `tblhotellocations` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('tblHotelLocations_id','int(11)','NO','PRI',NULL,'auto_increment');

INSERT INTO `tblhotellocations` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('location_id','int(11)','YES','',NULL,'');

INSERT INTO `tblhotellocations` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('hotel_id','int(11)','YES','',NULL,'');


/*
-- Query: desc tblHotelLanguages
-- Date: 2011-11-02 09:39
*/

INSERT INTO `tblhotelanguages` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('tblHotelLanguages_id','int(11)','NO','PRI',NULL,'auto_increment');

INSERT INTO `tblhotelanguages` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('language_id','int(11)','YES','',NULL,'');

INSERT INTO `tblhotelanguages` (`Field`,`Type`,`Null`,`Key`,`Default`,`Extra`) VALUES ('hotel_id','int(11)','YES','',NULL,'');
  • 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-26T15:32:37+00:00Added an answer on May 26, 2026 at 3:32 pm
    Select *
    from tbHotels h, tblFacilities f, tblHotelFacilities hf
    where f.facilitiesName IN (?,?,?) AND hf.facilityId = f.id 
    AND hf.hotelId = h.id
    

    This is a query for only facilities, u can add locations and languages….

    ?’s can be added like this,

    assuming u have an ArrayList containing names of facilities entered by user.

    String query = " Select * " +
    "from tbHotels h, tblFacilities f, tblHotelFacilities hf"+
    "where f.facilitiesName IN <facilities> AND hf.facilityId = f.id "+
    "AND f.hotelId = hf.hotelId";
    
    String x = "";
    int length = ArrayListOfFacilityNames.length();
    while(length>0) {
      x=x+"?, ";
      length = length-1;
    }
    //remove last "," from string x
    
    x=x.substring(0, x.length -1);
    
        //paste this string of facilities in main query 
    
       query = query.replace("<facilities>",x);
    
       // now ur query contains number of question marks equivalent to number of facilities      entered by user
    
       //make prepares statement with String query
    
       Iterator fnames = ArrayListOfFacilitiesNames.Iterator();
       int i=0;
       while(fnames.hasNext())
       {
         String name = fname.next();
         preparesStatement.setString(i,name)
         i++;
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to create an if statement in PHP that prevents a single post
I have just tried to save a simple *.rtf file with some websites and

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.