Returning a partial list

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

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: [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

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

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

- Dennis

Re: [dennisoneil] Returning a partial list

Hi Jason,

This works perfectly. Thanks so much for your help.

-Dennis

Re: [Jason] Returning a partial list

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.

Re: [dennisoneil] Returning a partial list

By Jason - April 16, 2010

Hi,

How we go about this really depends on exactly what you want to do. For example, we could change the code you just sent me to this:
<div>
<?php foreach($productRecords as $record): ?>
<?php if($record['square_footage']<2500): ?>
*RECORD*
<?php else: ?>
*CONDITION NOT MET CODE*
<?php endif ?>
<?php endforeach ?>
</div>


In this example, the *CONDITION NOT MET CODE* will execute when the variable $record['square_footage'] is not less than 2500. This means it will execute if it's equal to 2500, or greater than 2500.

Is this what you're looking for? Let me know.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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