Login | Sign up | Toll-Free: 1-800-752-0455



5 posts by 2 authors in: Forums > CMS Builder
Last Post: July 18, 2017


1.  My clients wants to be able to edit the story categories, so I have created a section called "Blog Categories".  Within this, they can create new categories as they go.  A story can belong to multiple categories.

2.  In the stories section, the client has a drop down to select which category (or more than one) which the story belongs to.  

3.  The problem:  if I use the below to only list the Adventure Education stories, all the stories appear even though 1/2 aren't marked as Adventure Education.

"where" => "`category` != 'Adventure Education'",

4.  Also, where the story belongs in several categories, is there a way to separate the categories (ie, tags), so there is a divider to some space between them? eg. <?php echo join(', ', $record['category:values']); ?>   produces a run on string of words without any real spacing between them.

Thanks in advance for your help!

Hi degreesnorth, 

For front end views you may actually be able to use the search features like this to automatically list the category you want: 

For example: yourViewer.php?category=Adventure Education

But if you need to do it with MySQL this should match a single category: 

"where" => " `category` = 'Adventure Education' ",

Or if you're searching a multi-value pulldown then the values are separated by tabs, so you can use this: 

"where" => " `category` LIKE '%\tAdventure Education'\t%",

% means "any characters and \t means tab.  So it matches your keyword surrounded by tabs anywhere in the string.

And for displaying the list of categories, your code should work.  what output do you see when you try <?php showme($record['category:values']); ?> or even <?php showme($record); ?>

Hope that helps!  Let me know what you find out.  Thanks!

Dave Edis - Senior Developer

Hi Dave

Thanks for responding.  

Unfortunately, I am getting an error of 

(when I use " marks)

// load records from 'blogs'
list($blogsRecords, $blogsMetaData) = getRecords(array(
'tableName' => 'blogs',
'loadUploads' => true,
"where" => " `category` LIKE '%\tAdventure education'\t%",

MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%) AND `blogs`.hidden = 0 ORDER BY dragSortOrder DESC' 

and when I change it to single ' (quote marks)

// load records from 'blogs'
list($blogsRecords, $blogsMetaData) = getRecords(array(
'tableName' => 'blogs',
'loadUploads' => true,
'where' => ' 'category' LIKE '%\tAdventure education'\t%',

Parse error: syntax error, unexpected 'Education' (T_STRING), expecting ')' 

Any other suggestions?

Thanks in advance

PS.  Also, I I want to add the blog categories to a page (so they are clickable, how do I use the <a href= ???> to make it go only to, for example, adventure education?

<?php foreach ($blog_categoriesRecords2 as $record): ?>
<ul class="list list-border angle-double-right">
<li><a href="#"><?php echo htmlencode($record['title']) ?></a></li>
<?php endforeach ?>

Hi Dave

I hadn't heard anything back so did a quick fix by using 

'where' => 'category LIKE "%Coaching%"',

It's not perfect and very clunky, but for now it works and it was urgent.  

It still hasn't resolved the issue of hyperlinking the categories (ie, so that you can click on any of the <?php echo join(', ', $record['category:values']); ?> - and I have not be able to find anything related in the forum.

Yet there was a post https://www.interactivetools.com/forum/forum-posts.php?page=1&Category-Pages-79365 which was sort of what I was after - enabling the client to add categories to blogs, but I couldn't follow the conversation trail.  I might have to contact you offline.