Grouping

4 posts by 2 authors in: Forums > CMS Builder
Last Post: February 6, 2017   (RSS)

Hi,

I can't find a way in the code generator for a WHERE statement ... so, can you tell me how I might group stuff? I am running a food menu categorised as Starters, Mains, Desserts. I want to achieve the following grouping for all three courses which previously I would have used a WHERE statement:

COURSE (e.g. Starts, Mains or Desserts)

Item

Item

Item

The cumbersome way I am doing it, is to hard code the Course name first and then use:

<h4>Starters</h4>
<?php if ($record['course']=="Starters"): ?>
    <div class="name-wrap">
        <div class="box">
            <h6 class="box_aside"><?php echo htmlencode($record['name_of_dish']) ?></h6>
            <span class="box_right"></span>
        </div>
        <p class="brd"><?php if($record['description']):?><?php echo htmlencode($record['description']) ?><?php endif; ?></p>
    </div>
<?php endif; ?>

Thanks

Terry

By ross - February 3, 2017

Hi Terry

Thanks for posting.

Let's take a look at how to setup a "where" statement with your code.

First off, my recommendation is to actually use three different "getRecords" so you can have one list for each course.

Next, let's suppose the code generator gives you the following:

// load record from 'meals'
  list($mealsRecords) = getRecords(array(
    'tableName'   => 'meals',
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));

Here's how you'd add a "where" to that:

// load record from 'meals'
  list($starters) = getRecords(array(
    'tableName'   => 'meals',
    'where'       => "course = 'starters'", // load starters
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));

Note: I'm assuming your table name is called "meals" so many sure to update that if it's something else instead.

See the "where" in that?  

To take this to the next step, you can duplicate that block twice more (giving you a total of 3).  

Make sure to adjust the "Where" part so it loads the right course. Also, make sure to change the variable name for "$starters". You can use $mains and $desserts.

Does this all make sense?

Let me know any questions.

Thanks! 

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By ross - February 6, 2017

Hi Terry

Glad you found an option that works for you.

Keep us up to date with how you are making out.

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/