Display of stories by multiple value lists
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!
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!
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.
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%',
'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!