Returning a partial list

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

By dennisoneil - April 8, 2010

Hello,

I've used CMSB on a handful of projects, but I'm now attempting a more advanced implementation.

My client for this projects is a home builder and I need to display a list page that segments his product offering by square footage (Square footage being a numerical field).

For example, I need to display:

<div>
foreach record with square footage less than 2500
</div>

<div>
for each record with square footage between 2500 and 3000
</div>

<div>
foreach record with square footage greater than 3000
</div>

I've searched the forum, but have not found an answer of similar example. Any help would be appreciated.
Thanks in advance.

Dennis

Re: [dennisoneil] Returning a partial list

By Jason - April 9, 2010

Hi Dennis,

The easiest way to do this would be like this:

First, make sure the records being returned are sorted by square footage:

<?php
list($productRecords,$productMetaData) = getRecords(array(
'tableName' => 'products',
'orderBy' => 'square_footage ASC',
));
?>


This will return all of the records. This is how we'll print it out to organize it into the different categories:

<div>
<?php foreach($productRecords as $record): ?>
<?php if($record['square_footage']<2500): ?>
*RECORD*
<?php endif ?>
<?php endforeach ?>
</div>

<div>
<?php foreach($productRecords as $record): ?>
<?php if($record['square_footage']>=2500 && $record['square_footager']<=3000): ?>
*RECORD*
<?php endif ?>
<?php endforeach ?>
</div>

<div>
<?php foreach($productRecords as $record): ?>
<?php if($record['square_footage']>3000): ?>
*RECORD*
<?php endif ?>
<?php endforeach ?>
</div>


All you need to do is change the names to match what you have in your database. Where it says *RECORD* you'll output whatever record information you want.

Hope that helps.
---------------------------------------------------
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] Returning a partial list

By dennisoneil - April 9, 2010

Thanks Jason! Exactly what I needed.

If I may follow up with an additional request/question...


This project has two major sections - A multi-record section of HOMES and a multi-record section of COMMUNITIES.

Not all the homes are available in all the communities, and the same home will have a different price in each community.

In each HOMES record, I have a field for a price in each community; i.e. Community ABC Price _______, Community XYZ Price _______.

What I need is this:

When displaying a COMMUNITYdetail page, I need to display a list of only the HOMES records that have an entry in the correct COMMUNITY_ABC_PRICE field.

I get that I can do <?php if ($homesRecord['price_communityABC'] != "" ): ?> show this <?php endif ?>

but what I need is for the "communityABC" part of the line above to change based on the COMMUNITYdetail page being displayed. This, unfortunately, it not yet something I now how to code.

Hopefully I've explained this sufficiently.

Thanks in advance for your help.

Re: [dennisoneil] Returning a partial list

By Jason - April 9, 2010

Hi,

I think we can get that done. I have a question.

When you go to the detail page with the different community, how is the community name displayed in the url?
(ex: detail.php?community_name=*COMMUNITYNAME*)

Also, what is the naming convention you use in your home table for prices? Is it price_*COMMUNITYNAME*?

Let me know.
Thanks
---------------------------------------------------
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] Returning a partial list

By dennisoneil - April 9, 2010

Great, thanks Jason.

The community detail page url would be:
/calvert-county-real-estate.php?COMMUNITY-NAME-123

The price fields are named as you guessed:
price_COMMUNITY_NAME

Thanks again. I look forward to your suggestion.

BTW- My intention is to use mod rewrite when I'm done to remove the "?" from the URL. I'm not sure if that's relevant to what you had in mind. Also, this working is more important than getting rid of the "?", so if its only possible with the "?" in place, then I'll leave it there.

-Dennis

Re: [dennisoneil] Returning a partial list

By Jason - April 12, 2010

Hi,

We can try this:

Anywhere above where you're going to output potential price information, put this line:
<?php $field="price_".$_SERVER['QUERY_STRING']; ?>

After that, you can use this line:
<?php if ($homesRecord[$field] != "" ): ?> show this <?php endif ?>

Give that a try and let me know how it goes.
---------------------------------------------------
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] Returning a partial list

By dennisoneil - April 13, 2010

Thanks so much Jason. I'll be testing this out soon and will share my results.

- Dennis

Re: [dennisoneil] Returning a partial list

By dennisoneil - April 15, 2010

Hi Jason,

This works perfectly. Thanks so much for your help.

-Dennis

Re: [Jason] Returning a partial list

By dennisoneil - April 16, 2010

Hi again Jason - one last question...

For this code:

<div>
<?php foreach($productRecords as $record): ?>
<?php if($record['square_footage']<2500): ?>
*RECORD*
<?php endif ?>
<?php endforeach ?>
</div>

How would I add a condition to display some code when there are no records fitting that criteria?

Naturally speaking:
When Plans <2500 square feet is none, then do this.

Thanks again for your help.