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 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/

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

By (Deleted User) - April 9, 2010

Guess what.

It does. Works perfectly.

Sheesh.

Thanks!

p.s. Mental Note - setting a list item value as blank in Dreamweaver does not do what you think it does. D'oh.