We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Mysql help

Development and Programming

julie p's avatar
julie p
282 posts
15 years ago
julie p's avatar julie p

Hi all. I am NOT a mysql pro, but need a custom mysql queries some I’m here for help. I’ve turned on the sql queries so I can see what is being called by tags that do nearly what I want. Here’s the EE code I’m using:

{exp:weblog:categories style="linear" category_group="5" weblog="classifieds" show_empty="no"}
   <li><a href="#{category_name}">{category_name}</a></li>
{/exp:weblog:categories}

That I believe results in:

{exp:query sql="SELECT DISTINCT(exp_categories.cat_id), parent_id FROM exp_categories LEFT JOIN exp_category_posts ON exp_categories.cat_id = exp_category_posts.cat_id LEFT JOIN exp_weblog_titles ON exp_category_posts.entry_id = exp_weblog_titles.entry_id WHERE group_id IN ('5') AND exp_weblog_titles.site_id IN ('1') AND exp_category_posts.cat_id IS NOT NULL AND exp_weblog_titles.status != 'closed' ORDER BY group_id, parent_id, cat_order"}
{category_id}
{/exp:query}

So a couple of things. This latter just spits out {category_id} instead of any content. But more importantly, I want to add another condition…

in layman’s terms: I want all category names from category 5 associated with the “classifieds” weblog that are not empty. I then want to narrow this list using only entries from “classifieds” that are in a particular “edition” via a relationship. Here’s my structure:

classifieds weblog: - category group 5 - relationship field to edition weblog (jan/feb/march)

classifieds page should be able to be edition limited… we don’t want to show a classified entry from last November, but only the current ones…

any help would be greatly appreciated!!!

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
15 years ago
Kevin Cupp's avatar Kevin Cupp

This query should at least get you the category names you want from group 5 that are assigned to entries, I’m not sure what you mean about the relationships.

SELECT DISTINCT exp_categories.cat_id , exp_categories.cat_name
FROM exp_categories
JOIN exp_category_posts ON exp_category_posts.cat_id = exp_categories.cat_id
WHERE exp_categories.group_id = 5

And change {category_id} to {cat_id} and you should see values popping up. Those tags should correspond to the ones in your SELECT statement, so to print the category name, put {cat_name}

       
julie p's avatar
julie p
282 posts
15 years ago
julie p's avatar julie p

ok - thanks. I decided to hire someone to write a plugin for me. I need the entries to be limited by a third factor (the edition weblog). Thanks for helping!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.