Link to home
Start Free TrialLog in
Avatar of kosmozzed
kosmozzed

asked on

cfloop / cfquery cf_tag "only for experts"

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="Attributes.zone" 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)
   </cfquery>
</cfloop>

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...
Avatar of kosmozzed
kosmozzed

ASKER

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>
            <cfif #attributes.zone# NEQ "0">AND (dbo.articles.articleZone = '#attributes.zone#')</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>
      </cfquery>

He doesn't look into a result where the view-result is (1,2)...
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...
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.
But according to your definition status is NEVER public.  The view is public.
status can be both public as well as never public...
ASKER CERTIFIED SOLUTION
Avatar of mmc98dl1
mmc98dl1
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial