
Jason
Staff
/ Moderator

Jan 24, 2012, 10:16 AM
Post #2 of 7
(1086 views)
Shortcut
|
|
Re: [dwelling] Blog Questions - Categories
[In reply to]
|
Can't Post
|
|
Hi Jeremy, It looks like you're well on your way to getting this to work, you just need to make a couple of adjustments. The first thing I would do is change the links that your categories are outputting to put the word "category" in the url. For example: www.ihelpinc.net/Blog/category.php?category=2 Next, we need to change how we're retrieving blog records. From what you've described, it sounds like your category list field in "blog" is a multi-value select. In CMS Builder, multi-value fields are stored as strings separated by tab (\t) characters. What we can do is look for the category variable in the URL. If we find it, create a custom WHERE clause to only retrieve records where that number appears in the list. For example:
$where = ""; if (@$_REQUEST['category']) { $where = "category LIKE '%\t".intval(@$_REQUEST['category'])."\t%'"; } list($blogRecords, $blogMetaData) = getRecords(array( 'tableName' => 'blog', 'allowSearch' => false, 'where' => $where, )); Note, you may need to change some names to match what is in your sections. Finally, when outputting your list of categories, you can use the mysql_count function to check if any blog records exist for that category, if not, skip it. Example:
<?php foreach ($categoryRecords as $category): ?> <?php if (!mysql_select("blog", "category LIKE '%\t".$category['num']."\t%'")) { continue; } ?> <a href = "category.php?category=<?php echo $category['num'];?>"><?php echo $category['title'];?></a> <?php endforeach ?> Hope this helps get you started. --------------------------------------------------- Jason Sauchuk - Programmer interactivetools.com Hire me! Save time by getting our experts to help with your project. http://www.interactivetools.com/consulting/
|