Display of stories by multiple value lists

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

Hi

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 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>
</ul>
<?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.

Thanks

By Dave - July 18, 2017

Hi degreesnorth, 

On the first issue.  I find adding spaces can help a lot.  Basically you just need to use different quotes on the inside of the string and can't quote the fieldname (or have to use `backticks` to do that).  So instead of this: 

'where' => ' 'category' LIKE '%\tAdventure education'\t%', 

Try this: 

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

The first one is comparing against the text 'category', the second one is comparing against the MySQL database column 'category'.

And for the link, the first step would be printing out the category, but your field may have multiple, so you'd need to decide what you want to do there.  In general, it's something like this: 

<li><a href="yourpage.php?category=<?php echo urlencode($record['category']); ?>"><?php echo htmlencode($record['title']) ?></a></li>

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com