Displaying results based on 'status'

9 posts by 3 authors in: Forums > CMS Builder
Last Post: November 27, 2015   (RSS)

By degreesnorth - November 19, 2015

Hi

I'm stuck on this one.  I have a list of properties which are either 'available', 'under offer' or 'leased'.  I have used the drop down function to select the status of each.

What I am wanting to do on the home page is display different properties under different headings such as:

1) new on market (display 4 (from the available))

2) under offer (display 4 listed as under offer) and

3) leased (display 4 (ideally the most recently) leased)

Any ideas of how I can go about doing this?

Thanks

Carole

By degreesnorth - November 22, 2015

Hi Jerry

Thanks for this.  It looks very confusing, but I'll try and wade thru it.

By Daryl - November 23, 2015

Hi Carole,

One way to do it is to have a query for each of the status and add where clause to select specific status.
For example:

// new on market
$newOnMarketPropertiesRecords = mysql_select('properties', 'status = "available" ORDER BY createdDate LIMIT 4');

// under offer
$underOfferPropertiesRecords  = mysql_select('properties', 'status = "under offer" ORDER BY createdDate LIMIT 4');

// leased
$leasedPropertiesRecords      = mysql_select('properties', 'status = "leased" ORDER BY createdDate LIMIT 4');

And then use foreach loop to display the contents under their designated headings:

// for "new on market" heading
foreach ($newOnMarketPropertiesRecords as $newOnMarketPropertiesRecord){
  echo htmlencode($newOnMarketPropertiesRecord['name']);
}

Hope this helps!

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com

By degreesnorth - November 24, 2015

Hi Daryl

I think this is assuming each of the status types are a different section within the cmsb (they aren't) - a property can be any of the available, under offer or leased (drop down) which changes the status on the single file.

I've tried the below and am getting endless errors.  

By gkornbluth - November 25, 2015

Hi Carole,

See if you can use something from this code from my FAQ page.

It uses a list field called category

You can use sort order to determine how the records are presented, so "newest first", would be 'orderBy' => 'createdDate DESC', as below.

Good luck,

Jerry Kornbluth

<?php
     // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
 $dirsToCheck = array('/path_to_your_server/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

<?php
list($faqRecords, $faqMetaData) = getRecords(array(
    'tableName'   => 'faq',
    'orderBy' => 'createdDate DESC',
  ));
  ?>
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FAQ</title>
</head>

<body>
<table width="100%" border="0" cellpadding="0">
  <tr>
    <td align="center" class="heading_font"><br />
      FAQ </td>
  </tr>
  <tr>
    <td align="center" class="text_font"> CLICK/TAP FOR ANSWERS... </td>
  </tr>
  <?php $old_group = ''; // init blank var.
foreach ($faqRecords as $record):
$group = $record['category:label']; // load sub-group value from record. ?>
  <tr>
    <td align="left" ><span class="text_font">
      <?PHP
if ($group != $old_group) {echo "<h2>$group</h2>";}?>
      </span>
      <?php   

if  (!preg_match("/^http:\/\//i", $record['url'])) {
 $record['url'] = "http://" . $record['url'];   }

?>
      <a class="special-link" href="
                            <?php echo $record['_link'] ?>" target="_blank">
      <?php $question = ($record['question']); ?>
      <?php $link_text = ($record['link_text']); ?>
      <span class="text_font-bold">- - <?php echo ucwords($question); ?></span><br />
      </a>
      <hr align="center" color="#<?php echo $nawa_colorsRecord['menu_background_color'] ?>" /></td>
  </tr>
  <?PHP $old_group = $group; // retain sub-group name before moving to new record. ?>
  <?php endforeach; ?>
</table>
</body>
</html>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Daryl - November 26, 2015

Hi Carole,

I wrote my example assuming that the properties are in one cmsb section, ie: "properties" and the status types are in a drop-down list field (not from separate sections) in that "properties" section.
And a property/record in "properties" section can have one of these status types: available, under offer or leased
Is that correct?

So for this line from my example:

// new on market
$newOnMarketPropertiesRecords = mysql_select('properties', 'status = "available" ORDER BY createdDate LIMIT 4');

We're pulling 4 records (LIMIT 4) from 'properties' section where 'status' is 'available'.
While the one below pulls 4 records from the same 'properties' section but, this time, the status of the records that we're pulling is 'under offer'

// under offer
$underOfferPropertiesRecords  = mysql_select('properties', 'status = "under offer" ORDER BY createdDate LIMIT 4');

As for the errors, if after replacing my example section/table name 'properties' with the actual section where you store your properties and the actual status type still returns some errors, can you please post the errors you've received?

Thanks,

Daryl Maximo
PHP Programmer - interactivetools.com

By degreesnorth - November 26, 2015

Hi Daryl

I'll give this one more go.

I am currently using

<?php

$count=0;

$maxCols=4;

?>
<?php foreach ($lease_warehouseRecords as $record): ?>   .... and then to close it

<?php endforeach ?>

<?php if (!$lease_warehouseRecords): ?>

No records were found!<br/><br/>

<?php endif ?>

So does that mean I replace this (err, I guess with ...

// new on market
$newOnMarketPropertiesRecords = mysql_select('properties', 'status = "available" ORDER BY createdDate LIMIT 4');

Tried that and it didn't work (as that also makes a list, and I need it to be columns)

By Daryl - November 27, 2015

Hi Carole,

The code that I posted are just examples so you might need to replace some variables and values.

I'm guessing that your properties are stored in 'lease_warehouse' table/section so you need to replace my example code's table name 'properties' with 'lease_warehouse' (replace it with correct table/section name if my guess is wrong).
Here's how the "new on market" MySql query and code to display it might look like:

<?php
// new on market
$newOnMarketPropertiesRecords = mysql_select('lease_warehouse', 'status = "available" ORDER BY createdDate LIMIT 4');
?>

<?php if (!$newOnMarketPropertiesRecords): ?>
   No records were found!<br/><br/>
<?php else; ?>
   <?php foreach ($newOnMarketPropertiesRecords as $record): ?> 
        Some code here..
   <?php endforeach ?>
<?php endif; ?>

Let me know if that works or post any errors you get if it didn't.

Thanks,

Daryl Maximo
PHP Programmer - interactivetools.com