Property Types with Subtypes, "We also have ..."

16 posts by 3 authors in: Forums > CMS Builder
Last Post: April 9, 2010   (RSS)

By Chris - April 7, 2010 - edited: April 7, 2010

Hi Alan,

I'm confused about why you would have an "Either" checkbox. If you're going to use checkboxes, I would imagine you'd want just:

[X] Let
[X] Buy

Alternately, you could use radio buttons (or a dropdown), in which case you'd have an "Either" option, but the browser would prevent people from selecting more than one option at a time:

( ) Let
( ) Buy
(o) Either

I don't think you need any JavaScript to get this working. Personally, I'd use radio buttons for this, so let's assume you'll use this HTML:

<input type="radio" name="let_buy" value="let" selected /> Let<br/>
<input type="radio" name="let_buy" value="buy" selected /> Buy<br/>
<input type="radio" name="let_buy" value="either" selected /> Either<br/>


Then you could use a little PHP to turn that form value into a where clause:

$where = '1'; // start with an "accept all" where condition (note that getRecords' allowSearch will add additional conditions for form keys which match fieldnames (i.e. "location"))

// add where condition for property_type
if (@$_REQUEST['property_type']) {
$property_typeCSV = join(',', $_REQUEST['property_type']);
$where .= " AND property_type IN (" . mysql_escape($property_typeCSV) . ")";
}

// add where condition for let/buy/either
if (@$_REQUEST['let_buy'] == 'let') {
$where .= " AND status = 'let'";
}
else if (@$_REQUEST['let_buy'] == 'buy') {
$where .= " AND status = 'buy'";
}
else if (@$_REQUEST['let_buy'] == 'either') {
// no filtering required
}


// load records
list($listingsRecords, $listingsMetaData) = getRecords(array(
'tableName' => 'listings',
'where' => $where,
));


The above code assumes you'll have a field called "status" which will either be 'let' or 'buy', but if I understand how your sale_price, p_o_a, and rental_price fields work, you can replace the code in red above with this:

if (@$_REQUEST['let_buy'] == 'let') {
$where .= " AND rental_price <> ''";
}
else if (@$_REQUEST['let_buy'] == 'buy') {
$where .= " AND (sale_price <> '' OR p_o_a <> '')";
}
else if (@$_REQUEST['let_buy'] == 'either') {
// no filtering required
}


The logic here is:

If the rental_price field is not blank, it's for-rental (or both.)
If either sale_price or p_o_a is not blank, it's for-sale (or both.)

Does that help? Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Property Types with Subtypes, "We also have ..."

By (Deleted User) - April 8, 2010

Logic prevailed - I managed to persuade the client that just the checkboxes to Let or Buy were sufficient.

Thankfully.

I will have a look at the logic for sale price/poa/rental price later today --> it looks great from first glance :).

I have to say, the support we are getting is superb, and I'm learning a heck of a lot from these code examples!

By (Deleted User) - April 8, 2010

Hi,

Okey dokey, because we are down to just the two checkboxes, the code is slightly different. This is what I have. This works for me, so I'm sharing it in case others are interested [:)]

search.php
Are you looking for property
<input type="checkbox" name="to_let" id="to_let" />
to Let or
<input type="checkbox" name="to_buy" id="to_buy" />
to Buy?</p>


list.php

$where = '1'; // start with an "accept all" where condition

// add where condition for property_type
if (@$_REQUEST['property_type']) {
$property_typeCSV = join(',', $_REQUEST['property_type']);
$where .= " AND property_type IN (" . mysql_escape($property_typeCSV) . ")";
}

// build on to cover 'to_buy' and 'to_let' checkboxes
if (@$_REQUEST['to_buy'] == 'on' && @$_REQUEST['to_let'] =='on') {
// do no filtering
} else if (@$_REQUEST['to_buy'] == 'on') {
// show purchase properties
// p_o_a is a checkbox!
$where .= " AND (price <> '' OR p_o_a = '1')";
} else if (@$_REQUEST['to_let'] =='on') {
// show rental properties
$where .= " AND rental_price <> ''";
}

// load records
list($propertiesRecords, $propertiesMetaData) = getRecords(array(
'tableName' => 'properties',
'where' => $where,
));


I also found it incredibly useful to stick
<?php echo $where ?>
at the top of the content area of list.php so I could see the where clause being built up. Never underestimate the power of debug statements!

*cough*p_o_a is a checkbox*cough*

Also - checking that your code actually /works as expected/ before posting helps too. <.< >.> nothing to see here [;)]

By (Deleted User) - April 8, 2010

Right, now I know this one is simple, and I'm being a thicky.

We have a dropdown:

<select name="location">
<option value="1">City Centre</option>
<option value="2">City Suburbs / Business Parks</option>
<option value="3">Other small town</option>
<option value="4">And another small town</option>
<option value="5">Rest of County</option>
</select>


These directly map to the field "locations" which has been set up in the database. Locations is of type 'list'.

You can choose which location you want on the filter screen, and it will show you the properties for that location.

Now, excuse me for a minute here.

*wunch* *wunch* *wunch* *wunch*

Ok, thats better. That was me just banging my head on the desk.

How do I enable an "All Locations" option?

I tried adding

<option >All</option>

but that doesn't work. I seem to need to be able to simulate the Location parameter not being passed at all, as far as I can see, and I'm not sure how to do that.

I also considered using a magic number, e.g., -999, for the value, and trapping it on the list page, but then I realised that the filtering is kinda already done by the time I get to it, and it has already tried to find all locations with the location id -999, and got none.

Then my head imploded.

I have rifled through all the posts I can see, and checked out the latest CMS cookbook, but no joy.

By Jason - April 8, 2010

Hi,

try:

<option value="">All</option>

Let me know if that works.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/