SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast rajeshgs's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating a hotel directory

    Hi All,

    I want to categorize hotels in a mySQL DB, with respect to various features like city, location type(beach, metro, farm, hill station,..), star (5 star, 4 star,...), facilities (bar, mall, ....) and so on.

    I arrived at a logic to put a category code with each hotel to identify whether it comes under a specific category. the idea is to store id numbers in the following format:

    XXXYYYAAABBBCCCDDD , where
    XXX is the root id
    YYY is sub id
    AAA is a separate catg under YYY and so on.

    But the glitch is that, by browsing this directory, you should arrive at a hotel name in more than one way.

    how can I arrive at a solution. please help

    Rajesh

  2. #2
    SitePoint Enthusiast aivarannamaa's Avatar
    Join Date
    Sep 2002
    Location
    Estonia
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand your problem like this:

    * user specifies the features he needs, for example using html form with a checkbox, select or text input for each feature
    * system responds with a list of hotel names that have those features.

    I don't think you should encode hotel features into one number, instead, use a special field in your hotels table for each feature. If the value in such field is 1 (or boolean true, if your database has boolean type) then hotel has this particular feature, otherwise not.

    You checkboxes in the form should also have their value being '1' (or 'true').

    PHP Code:

    $conditions 
    = array();

    // $beach and $stars come from form

    if ($beach) {
        
    $conditions[] = "beach = 1"// or "beach = true"
    }

    if (
    $stars) {
        
    $conditions[] = "stars = $stars"
    }

    // and so on

    $sql "select id, name, and_so_on from hotels";

    if (
    count ($conditions) > 0) {
        
    $sql .= "where";
        
    $sql .= implode (" and"$conditions); // implode glues conditions together with 'and'-s
    }

    // execute query and show the results 
    Hope this gets you started.

    Aivar
    Last edited by aivarannamaa; Sep 28, 2002 at 03:31.

  3. #3
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would suggest re-thinking the structure, so I've moved this thread here

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •