Question for Where statement

6 posts by 3 authors in: Forums > CMS Builder
Last Post: November 11, 2009   (RSS)

By avrom - November 7, 2009

Hi guys,

I need to sort information from 2 specific records in a list section called properties:

list($propertiesRecords, $propertiesMetaData) = getRecords(array(
'tableName' => 'properties',
));


The 2 records to display are based on two values from a detail viewer.

$home_pageRecord['property_1']
and
$home_pageRecord['property_2']

How would I insert these two values property_1 and property_2 into the where clause for the properties viewer on this page ?

Thanks !
Avrom

Re: [virgodesign] Question for Where statement

By Damon - November 11, 2009

Hi Avrom,

Let's review by email what the published content output generated should be. Then we can figure out the code to get there. :)
Cheers,
Damon Edis - interactivetools.com

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

Re: [virgodesign] Question for Where statement

By Dave - November 11, 2009 - edited: November 11, 2009

Hi Avrom,

I've reviewed the email details you sent in. I think the easiest way to do this is with 3 queries as follows:

// load featured property numbers
list($home_pageRecords, $home_pageMetaData) = getRecords(array(
'tableName' => 'home_page',
'allowSearch' => false,
));
$homepageRecord = @$home_pageRecords[0]; // get first record

// load first property
list($featuredProperties, $propertiesMetaData) = getRecords(array(
'tableName' => 'properties',
'where' => " num = '" .mysql_real_escape_string($homepageRecord['property_1']). "' ",
'allowSearch' => false,
));
$firstProperty = @$featuredProperties[0]; // get first record

// load second property
list($featuredProperties, $propertiesMetaData) = getRecords(array(
'tableName' => 'properties',
'where' => " num = '" .mysql_real_escape_string($homepageRecord['property_2']). "' ",
'allowSearch' => false,
));
$secondProperty = @$featuredProperties[0]; // get first record


And you'd display their values like this:
Address: <?php echo $secondProperty['address'] ?><br/>

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [virgodesign] Question for Where statement

By Dave - November 11, 2009

Try changing recordNum to num. I updated my original post to show that.

If there's still errors attach the viewer file and I'll take a look.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [virgodesign] Question for Where statement

By avrom - November 11, 2009

Hi Dave,

OK that's perfect !! :)) I made a small edit to preserve the coding in my featured_properties module. I'm sure these can now be combined into one query, AND statement in Where clause with limit => 2, but not quite sure how to do that:

// load first featured property
list($featuredProperties, $propertiesMetaData) = getRecords(array(
'tableName' => 'properties',
'where' => " num = '" .mysql_real_escape_string($home_pageRecord['property_1']). "' ",
'allowSearch' => false,
));
$featuredProperty[0] = @$featuredProperties[0]; // get first record

// load second featured property
list($featuredProperties, $propertiesMetaData) = getRecords(array(
'tableName' => 'properties',
'where' => " num = '" .mysql_real_escape_string($home_pageRecord['property_2']). "' ",
'allowSearch' => false,
));
$featuredProperty[1] = @$featuredProperties[0]; // get second record

OK, thanks again, and please invoice for the time on this ^^ :))

Cheers
Avrom