Display of stories by multiple value lists

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

By Dave - July 5, 2017

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: 
https://www.interactivetools.com/docs/cmsbuilder/viewer_search.html

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
interactivetools.com

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