PDA

View Full Version : database/flash/cf stuff


dex002
08-02-2005, 02:43 AM
Ok, so this is a drag. I am doing something pretty simple and it kind of works, but I can't do it simply and I know there's a much better way.

This is my CFM code:

<cfquery name = "getGigsFlash" dataSource = "*******">
select gig_id, gig, gig_date, venue, address, time, phone, cost, highlight, date_format(gig_date, '%D %M %Y') as fgig_date FROM gigs
WHERE gig_date >= NOW() ORDER BY gig_date
</cfquery>
<cfset queryindex="1">
<cfset tempStruct = StructNew()>
<cfset tempStruct.gig_id1 = getGigsFlash.gig_id>
<cfset tempStruct.gig1 = "<b>" & getGigsFlash.gig[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.gig_date1 = "<b>" & getGigsFlash.fgig_date[#queryindex#] & "</b>">
<cfset tempStruct.venue1 = "<b>" & getGigsFlash.venue[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.address1 = "<b>" & getGigsFlash.address[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.time1 = "<b>" & " from " & getGigsFlash.time[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.phone1 = "Ph - " & "<b>" & getGigsFlash.phone[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.cost1 = "Cost - " & "<b>" & getGigsFlash.cost[#queryindex#] & "<br>" & "------------------------------" & "<br>">
<cfset tempStruct.highlight1 = getGigsFlash.highlight[#queryindex#]>

<cfset queryindex="2">
<cfset tempStruct.gig_id2 = getGigsFlash.gig_id[#queryindex#]>
<cfset tempStruct.gig2 = "<b>" & getGigsFlash.gig[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.gig_date2 = "<b>" & getGigsFlash.fgig_date[#queryindex#] & "</b>">
<cfset tempStruct.venue2 = "<b>" & getGigsFlash.venue[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.address2 = "<b>" & getGigsFlash.address[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.time2 = "<b>" & " from " & getGigsFlash.time[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.phone2 = "Phone - " & "<b>" & getGigsFlash.phone[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.cost2 = "Cost - " & "<b>" & getGigsFlash.cost[#queryindex#] & "<br>" & "------------------------------" & "<br>">
<cfset tempStruct.highlight2 = getGigsFlash.highlight[#queryindex#]>

<cfset queryindex="3">
<cfset tempStruct.gig_id3 = getGigsFlash.gig_id[#queryindex#]>
<cfset tempStruct.gig3 = "<b>" & getGigsFlash.gig[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.gig_date3 = "<b>" & getGigsFlash.fgig_date[#queryindex#] & "</b>">
<cfset tempStruct.venue3 = "<b>" & getGigsFlash.venue[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.address3 = "<b>" & getGigsFlash.address[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.time3 = "<b>" & " from " & getGigsFlash.time[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.phone3 = "Phone - " & "<b>" & getGigsFlash.phone[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.cost3 = "Cost - " & "<b>" & getGigsFlash.cost[#queryindex#] & "<br>" & "------------------------------" & "<br>">
<cfset tempStruct.highlight3 = getGigsFlash.highlight[#queryindex#]>

<cfset queryindex="4">
<cfset tempStruct.gig_id4 = getGigsFlash.gig_id[#queryindex#]>
<cfset tempStruct.gig4 = "<b>" & getGigsFlash.gig[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.gig_date4 = "<b>" & getGigsFlash.fgig_date[#queryindex#] & "</b>">
<cfset tempStruct.venue4 = "<b>" & getGigsFlash.venue[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.address4 = "<b>" & getGigsFlash.address[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.time4 = "<b>" & " from " & getGigsFlash.time[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.phone4 = "Phone - " & "<b>" & getGigsFlash.phone[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.cost4 = "Cost - " & "<b>" & getGigsFlash.cost[#queryindex#] & "<br>" & "------------------------------" & "<br>">
<cfset tempStruct.highlight4 = getGigsFlash.highlight[#queryindex#]>

<cfset queryindex="5">
<cfset tempStruct.gig_id5 = getGigsFlash.gig_id[#queryindex#]>
<cfset tempStruct.gig5 = "<b>" & getGigsFlash.gig[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.gig_date5 = "<b>" & getGigsFlash.fgig_date[#queryindex#] & "</b>">
<cfset tempStruct.venue5 = "<b>" & getGigsFlash.venue[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.address5 = "<b>" & getGigsFlash.address[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.time5 = "<b>" & " from " & getGigsFlash.time[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.phone5 = "Phone - " & "<b>" & getGigsFlash.phone[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.cost5 = "Cost - " & "<b>" & getGigsFlash.cost[#queryindex#] & "<br>" & "------------------------------" & "<br>">
<cfset tempStruct.highlight5 = getGigsFlash.highlight[#queryindex#]>

<cfset queryindex="6">
<cfset tempStruct.gig_id6 = getGigsFlash.gig_id[#queryindex#]>
<cfset tempStruct.gig6 = "<b>" & getGigsFlash.gig[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.gig_date6 = "<b>" & getGigsFlash.fgig_date[#queryindex#] & "</b>">
<cfset tempStruct.venue6 = "<b>" & getGigsFlash.venue[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.address6 = "<b>" & getGigsFlash.address[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.time6 = "<b>" & " from " & getGigsFlash.time[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.phone6 = "Phone - " & "<b>" & getGigsFlash.phone[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.cost6 = "Cost - " & "<b>" & getGigsFlash.cost[#queryindex#] & "<br>" & "------------------------------" & "<br>">
<cfset tempStruct.highlight6 = getGigsFlash.highlight[#queryindex#]>

<cfset queryindex="7">
<cfset tempStruct.gig_id7 = getGigsFlash.gig_id[#queryindex#]>
<cfset tempStruct.gig7 = "<b>" & getGigsFlash.gig[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.gig_date7 = "<b>" & getGigsFlash.fgig_date[#queryindex#] & "</b>">
<cfset tempStruct.venue7 = "<b>" & getGigsFlash.venue[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.address7 = "<b>" & getGigsFlash.address[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.time7 = "<b>" & " from " & getGigsFlash.time[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.phone7 = "Phone - " & "<b>" & getGigsFlash.phone[#queryindex#] & "</b>" & "<br>">
<cfset tempStruct.cost7 = "Cost - " & "<b>" & getGigsFlash.cost[#queryindex#] & "<br>" & "------------------------------" & "<br>">
<cfset tempStruct.highlight7 = getGigsFlash.highlight[#queryindex#]>


<cfdump var="#tempStruct#">
<cfset Flash.Result = tempStruct>

and here's my AS in the movie:

import mx.remoting.Service;
import mx.remoting.PendingCall;
import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;
import mx.remoting.debug.NetDebug;
NetDebug.initialize()

var CFMService:Service = new Service(
"http://127.0.0.1:8500/flashservices/gateway",
//"http://www.*****.***/flashservices/gateway",
null,
"audience.cf",
//"????"
null,
null);
var pc:PendingCall = CFMService.GetGigsFlash();
pc.responder = new RelayResponder(this, "GetGigsFlash_Result", "GetGigsFlash_Fault");

function GetGigsFlash_Result( re:ResultEvent ):Void {
//trace( re.result.GIG_ID );
//trace( re.result.GIG );
//trace( re.result.GIG_DATE );
//trace( re.result.VENUE );
//trace( re.result.TIME );
//trace( re.result.ADDRESS );
//trace( re.result.PHONE );
//trace( re.result.COST );
//trace( re.result.HIGHLIGHT );
gigs_txt.html=true;
//gigs_txt="loading...";
var gigs=
re.result.GIG1 + re.result.GIG_DATE1 + re.result.TIME1 + re.result.VENUE1 + re.result.ADDRESS1 + re.result.PHONE1 + re.result.COST1
+ re.result.GIG2 + re.result.GIG_DATE2 + re.result.TIME2 + re.result.VENUE2 + re.result.ADDRESS2 + re.result.PHONE2 + re.result.COST2
+ re.result.GIG3 + re.result.GIG_DATE3 + re.result.TIME3 + re.result.VENUE3 + re.result.ADDRESS3 + re.result.PHONE3 + re.result.COST3
+ re.result.GIG4 + re.result.GIG_DATE4 + re.result.TIME4 + re.result.VENUE4 + re.result.ADDRESS4 + re.result.PHONE4 + re.result.COST4
+ re.result.GIG5 + re.result.GIG_DATE5 + re.result.TIME5 + re.result.VENUE5 + re.result.ADDRESS5 + re.result.PHONE5 + re.result.COST5
+ re.result.GIG6 + re.result.GIG_DATE6 + re.result.TIME6 + re.result.VENUE6 + re.result.ADDRESS6 + re.result.PHONE6 + re.result.COST6
+ re.result.GIG7 + re.result.GIG_DATE7 + re.result.TIME7 + re.result.VENUE7 + re.result.ADDRESS7 + re.result.PHONE7 + re.result.COST7;
gigs_txt.htmlText = gigs;
//if (re.result.HIGHLIGHT1=="true"){
// gigs_txt.textColor=0xff0000;
//}
trace(gigs)
}

function GetGigsFlash_Fault( fe:FaultEvent ):Void {
gigs_txt.htmlText = "Sorry, there is a problem. Please try again."
}

As you can see, its very convoluted and actually doesn't quite do what I want. It all displays ok, but because I've had to hard-code a finite number of 'gigs', if the CF query only returns a couple of gigs, then the movie still displays the headers for the remaining gigs anyway, which looks really crap. I need to figure out how to loop and append to a struct or something like that.

Also, you see I've had to do my HTML in the CFM which is bad. I can't figure out how to get the HTML to work when its coded in Flash.

Anyway, and advice I could get would be awesome.

Thanks, Dex.

dex002
08-08-2005, 06:38 AM
I got the answer from another site in a completely unrelated post. Here's how it works:

<cfset gigArray = arrayNew(1)>

<cfloop query="getGigsFlash">

<cfset gigArray[arrayLen(gigArray) + 1] = structNew()>
<cfset gigArray[arrayLen(gigArray)].gig_id = getGigsFlash.gig_id>
<cfset gigArray[arrayLen(gigArray)].gig = getGigsFlash.gig>
<cfset gigArray[arrayLen(gigArray)].venue = getGigsFlash.venue>
<cfset gigArray[arrayLen(gigArray)].address = getGigsFlash.address>
<cfset gigArray[arrayLen(gigArray)].time = getGigsFlash.time>
<cfset gigArray[arrayLen(gigArray)].phone = getGigsFlash.phone>
<cfset gigArray[arrayLen(gigArray)].cost = getGigsFlash.cost>
<cfset gigArray[arrayLen(gigArray)].highlight = getGigsFlash.highlight>
<cfset gigArray[arrayLen(gigArray)].fgig_date = getGigsFlash.fgig_date>

</cfloop>

<cfreturn gigArray>

Its just dynamically creating an Array of Structs.