SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,

    I am working on a classifieds project. I have thousands of records listed in different categories.

    In the first screen, the category and the city is selected. Then, according to the category, a new list of attributes are displayed. For example, if the visitor(he) selects apartments and new york in the first screen, he is then asked to select which suburbs he would like to search in, and how many bedrooms he would like the apartment to have. There I have 2 problems.
    One of them is, how do I handle if he doesn't care how many bedrooms the apartment has. I know how to handle if he selects 2 or 3 or some other number, but what if he selects doesn't matter. How can I use this information when I make a search.

    Second, how do I handle the selection of more than one suburb and again what if he checks doesn't matter.

    My basic problem is that I am not able to handle organizing the search parameters in these 2 cases.

    A very similar sample can be seen at www.rent.net

    This is a very urgent case and any help is appreciated.

    Sorry, if I haven't been able to make it clear but it is a complicated thing to explain.

    thank you

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by keko
    how do I handle if he doesn't care how many bedrooms the apartment has.
    You could have a special "don't care" option in the list with a recognizable value (say, -1). Then in your PHP script, you could structure the WHERE clause of your MySQL differently depending on the selected option. Here's a hand-wavy example:

    Code:
    if ($bedrooms == -1) {
      // don't care about bedroms
      $bedroomswhere = "";
    } else {
      $bedroomswhere = "numbedrooms = '$bedrooms' AND"
    }
    
    $sql = "SELECT * FROM apartments WHERE $bedroomswhere visible = 'YES'";
    ...
    Second, how do I handle the selection of more than one suburb and again what if he checks doesn't matter.
    If you're passing the suburbs as an array (i.e. <input type=checkbox name="suburbs[]" ...>), then once again you should be able to build a variable containing an appropriate SQL fragment that you can plug into your query to get the results you're after.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I pass suburbs as an array? I don't have experience about how to use arrays in PHP. I have general information about arrays and I know how to use them in C, though.

    thank you

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Here's the relevant section of the PHP manual. If it doesn't make sense to you, let me know!

    http://www.php.net/manual/en/language.types.array.php
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


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
  •