Link to home
Start Free TrialLog in
Avatar of Kenny Devorak
Kenny DevorakFlag for United States of America

asked on

CFGrid Help

I need help creating a link inside a CFGrid.  Below is my code.  The problem is the output the code is generating.

The ouput:
http://mymobisaver.com/detailcoupon.cfm?CFGRIDKEY=38,Tammy's%20Oasis%20inside%20Cuttin'%20It%20Up!,25%25%20off%20%0D%0AHis%20&%20Hers%20Fragrances%20,Cuyahoga%20Falls,02-09-12

All I want the link to contain is:
http://mymobisaver.com/detailcoupon.cfm?CFGRIDKEY=38

Below is my Code:
<cfform name="CouponForm" format="html">
              <cfgrid name="parkGrid" selectmode="row" format="html" pagesize="8" width="580" bind="cfc:listCoups.getParks({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})">
                <cfgridcolumn name="Cid" header="id" display="no">
                <cfgridcolumn name="businessName" width="200" textcolor="Blue" header="Business Name" href="detailcoupon.cfm" hrefkey="id"/>
                <cfgridcolumn name="cDescription" width="200" header="Coupon" href="detailcoupon.cfm" hrefkey="id" />
                <cfgridcolumn name="city" width="110" header="City" href="detailcoupon.cfm" hrefkey="id" />
                <cfgridcolumn name="NEWexpDate" width="70" header="Exp Date" href="detailcoupon.cfm" hrefkey="id" />
              </cfgrid>
            </cfform>

Open in new window

Avatar of RickEpnet
RickEpnet
Flag of United States of America image

I think we need to take a look at your CFC and the query in it. Do you ahve any idea why your ID field is giving you all the extra information.

38 is all you want but it is givings you all this extra.

38,Tammy's Oasis inside Cuttin' It Up!,25% off His

Myself I normally only have one column with a hrefkey="id"

Avatar of Kenny Devorak

ASKER

Here is the code in my CFC:
<cffunction name="restaurants" access="remote" returntype="struct">
	<cfargument name="page" required="true" />
	<cfargument name="pageSize" required="true" />
	<cfargument name="gridsortcolumn" required="true" />
	<cfargument name="gridsortdirection" required="true" />
	
	<cfif arguments.gridsortcolumn eq "">
		<cfset arguments.gridsortcolumn = "businessName" />
		<cfset arguments.gridsortdirection = "asc" />
	</cfif>
    
	<cfset todayDate = Now()>
	<cfquery name="ListCoups" datasource="security">
SELECT  *, DATE_FORMAT(expdate, '%m-%d-%y') AS NewExpDate, coupon.id AS cID
FROM     coupon,member
WHERE  coupon.memberid=member.id and coupon.catagoryid=1 and coupon.expdate>#todayDate#
ORDER BY coupon.expdate asc
	</cfquery>

	<cfreturn queryconvertforgrid(listCoups, page, pagesize) />
</cffunction>

Open in new window

Avatar of _agx_
> Myself I normally only have one column with a hrefkey="id"

What happens if you try Rick's suggestion? ie Only make 1 column a link instead of all of them.

From your code I can see you must have multiple field with the name ID coupon.id and member.id.

How does the grid know which ID to use? What about if you changed the grid to show the cID like this?

<cfform name="CouponForm" format="html">
              <cfgrid name="parkGrid" selectmode="row" format="html" pagesize="8" width="580" bind="cfc:listCoups.getParks({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})">
                <cfgridcolumn name="Cid" header="id" display="no">
                <cfgridcolumn name="businessName" width="200" textcolor="Blue" header="Business Name" href="detailcoupon.cfm" hrefkey="cid"/>
                <cfgridcolumn name="cDescription" width="200" header="Coupon" href="detailcoupon.cfm" hrefkey="cid" />
                <cfgridcolumn name="city" width="110" header="City" href="detailcoupon.cfm" hrefkey="cid" />
                <cfgridcolumn name="NEWexpDate" width="70" header="Exp Date" href="detailcoupon.cfm" hrefkey="cid" />
              </cfgrid>
            </cfform>
> you must have multiple field with the name ID coupon.id and member.id.

Oh, I missed the evil SELECT *.  If that's the real problem, better to modify the underlying SELECT instead to eliminate the ambiguity IMO. Only include the columns you're using in the grid. No reason to return extra data if it's not being used.
That does not fix my problem with the HTML link though.  I do agree I should not have the evil SELECT * in my code.  I'm going to get rid of it.
What field(s) is this information coming from?

Tammy's Oasis inside Cuttin' It Up!,25% off His
ID
BName
CName
CDisclaimer
Baddress
Bcity
BState
Bzip
EXPDate

Which one of those columns contains the data values Rick posted?
Bname
Cname
So that field is getting into the Variable ID some how. agx do you see how that is happening? I do not see it.
I should say those fields
I have an idea for a work around.  I did a cfoutput on the variable to see exactly what it contain and here is the result.

26,Spc Sports,10% off any retail purchase! ,Mentor,12-31-11

Is there away to strip the contents of the string so I only get the first set of numbers?  
Keep everything untill you get to the first comma.
I guess I should make that a question.  Leave this open to see if anyone can fix it.
That is not the correct way of doing it. The variable should only contain the number. How is that orher data getting in there? That is why I ask which field that data was in.
If you want to strip it out it is pretty easy to do. When I get back to a computer I can write it out or maybe agx would post it.
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America 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