available, sold, coming soon categories

10 posts by 3 authors in: Forums > CMS Builder
Last Post: March 8, 2018   (RSS)

By leo - January 16, 2018

Hi,

Thanks for your inquiry. And yes, CMS has helper functions to filter records by its parameters. Depending on your website structure, you will have different options to do it.

Let me know if you have any questions about how it can be done!

Thanks,

Leo - PHP Programmer (in training)
interactivetools.com

By TheSeen - March 2, 2018

Hi Leo ... yes interested to learn how this can be done now, what's the best way forward?

By leo - March 2, 2018

Hi,

According to the description, I assume you want to be able to filter cars based on their status (sold/new etc.) when getting the records from the database. You can add a new field "status" to the cars section, make it a pulldown with the possible status you want. And on the front-end pages you can add a where statement to filter the records you get from getRecords like this:

list($carsRecords, $carsMetaData) = getRecords(array(
  'tableName' => 'cars',
  'where' => 'status = ' . $status,
  ...
));

In this example, the $status variable will be the value of the status field that you want of the cars records.

Hope this helps and let me know if you have any questions!

Thanks,

Leo - PHP Programmer (in training)
interactivetools.com

By TheSeen - March 5, 2018 - edited: March 5, 2018

Hi Leo ... I tried that but I'm getting an error on the test page.

I've uploaded the head code and also code in the html calling in records and also screen grab of the error when visiting the page.

Is there anything you can see that I need to do?

I added the new field called 'statuss' in the CMS as it said 'status' was a reserved field. This is running from a multiple section call 'available'.

best

Adrian

Attachments:

01.jpg 320K

02.jpg 239K

03.jpg 162K

By leo - March 5, 2018

Hi Adrian,

Sorry for the confusion. Basically you need to define $statuss first before passing in to the where statement. For example, your statuss field in CMS is a list that contains following values:

1|Available
2|Sold
3|New

* This is the default CMS list value format, the number on the left represents the actual value of the option and the text on the right represents the label

And on the page with records that marked as "Available", you can do this:

$statuss = 1 // 1 is the value of "Available" option
list($carsRecords, $carsMetaData) = getRecords(array(
  'tableName' => 'cars',
  'where' => 'status = ' . $status,
  ...
));

Or even more straightforward if you think this page won't need to get other records:

list($carsRecords, $carsMetaData) = getRecords(array(
  'tableName' => 'cars',
  'where' => 'status = 1',
  ...
));

Hope this helps you get what you want and let me know if you have any questions!

Thanks,

Leo - PHP Programmer (in training)
interactivetools.com

By Dave - March 6, 2018

Hi Adrian, 

Another option is to use the built-in searching features: 
https://www.interactivetools.com/docs/cmsbuilder/viewer_search.html

So for example if your field was called 'status' and the value was 'sold' you could add this to the URL to only show sold listings: 

yourviewer.php?status=sold

This way, you can create multiple links to the same page that show different listings.

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

By TheSeen - March 7, 2018

Thanks both.

I've noticed that it's not going to be suitable for the website as the sold and available sections have some different graphic markings in their html template. So I will simply recreate the car when it becomes sold.

I'm sure the advise will come in useful for future sites though so thanks.

By Dave - March 7, 2018

Hi Adrian, 

Ok, sounds good.  For future reference, one other thing you can do when using these kinds of queries: ?status=sold

Is to check for them and show different images or headings, eg: 

<?php if (@$_REQUEST['status'] == 'sold'): ?>
  <h1>Sold Listings</h1>
<?php else: ?>
  <h1>Default Title</h1>
<?php endif ?>

Dave Edis - Senior Developer
interactivetools.com

By TheSeen - March 8, 2018

Very useful .. thanks David.

You are legends.