cfloop / cfquery cf_tag "only for experts"

Posted on 2006-05-03
Last Modified: 2013-12-24
Hi there,

This is my question:

I am creating a CF_TAG wich i can use to display an amount of articles on specific page.
This is my cf_tag:  <cf_article view="2" status="1" zone="100" max_articles="5">
                            VIEW is public (2) or not public (1)
                            STATUS is online (1) or offline (2)
                            ZONE is page where i place articles
                            MAX_ARTICLES is amount of articles i wish to display

Then i create a list of attributes:
<cfparam name="Attributes.view" default="1,2">
<cfparam name="Attributes.max_articles" default="1">
<cfparam name="" default="0">
<cfparam name="Attributes.status" default="1,2">

Then i create my query:
<cfloop index="createArt" from="1" to="#attributes.max_articles#">
   <cfquery name="getArticles" datasource="database">
   select * from articles
   where article ... (here i am already stuck, tried a dozens options)

Problem is: that it is possible that an article can be in a view (1) and in the database be 1,2...

And here I would need to have an output (i've got already the DESIGN for my table-output)... just need the <cfloop or cfoutput tags...
Question by:kosmozzed

    Author Comment

    This is my query:

    <cfquery name="getArticle" datasource="#database_src#">
                SELECT      *
                FROM         dbo.articles
                WHERE        <cfif #attributes.status# NEQ "">(dbo.articles.articleStatus = '#attributes.status#')<cfelse>
                dbo.articles.articleStatus IN ('#attributes.status#')
                <cfif NEQ "0">AND (dbo.articles.articleZone = '')</cfif>
                <cfif #attributes.view# NEQ "0" AND #ListLen(attributes.view, ',')# EQ 1>AND (dbo.articles.articleView = '#attributes.view#')
                <cfelseif #attributes.view# NEQ "0" AND #ListLen(attributes.view, ',')# GT 1>AND dbo.articles.articleView IN ('#attributes.view#')
    <cfelse><cfthrow message="bad query"></cfif>

    He doesn't look into a result where the view-result is (1,2)...
    LVL 35

    Expert Comment

    First of all I don't know why you labeled the subject "only for experts"  since looking at your code there are many things even some beginners may be able to point out as not very good coding.  For example you have # in <cfif ...> tags when it is inefficient to do so and not needed.  Also you do not use <cfqueryparam, which makes you vulnerable to dangerous SQL injection attacks.

    However, regarding your question - I am totally confused.

    How can you have "STATUS is online (1) or offline (2)" and then have the default be "1,2"

    It is both on and offline?  You are going to need to explain better what you are after here...

    Author Comment

    Getting a result if the status is public or offline is no problem at all.  Getting a result when the status is public and also offline is the point.
    LVL 35

    Expert Comment

    But according to your definition status is NEVER public.  The view is public.

    Author Comment

    status can be both public as well as never public...
    LVL 12

    Accepted Solution

    How about you just assume everything is not public, and if view = 1 then its also public. Then in your database you only need to store 1 or 0. Then you query for internal pages doesnt specify view and for a public pages goes for view = 1.

    Featured Post

    Superior storage. Superior surveillance.

    WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

    Join & Write a Comment

    In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
    Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now