Solved

Complicated Question

Posted on 2001-06-26
4
142 Views
Last Modified: 2013-12-24
Ok Im creating a raffle system for personal use.
Now basically what it is, someone will send their payment to me via PAYPAL. Once I confirm it, I will go into my raffle application and type in their name email and the the number of tickets they have purchased based on how much they have sent.

So can someone help with making the following example in a cold fusion app.
Please note I know I can the users name thrown into the database for each seperate ticket they purchase but they will get to big.
--------------------
Example (non electronic):
John buys 10 tickets
Mary buys 20;
Peter buys 15;
I throw all 45 tix into a hat and randomly pick one, now how would I do this electronically?

Sorry I know this seems confusing.

If someone would like I would love it if they created the thing for me, it is a small app. but I only have these 200 points.
0
Comment
Question by:hansamryan
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
CF_Spike earned 200 total points
ID: 6229526
ok,

I can't send you the database, but the structure is as follows:

Table: Raffle
Field1 User
Field2 Tickets

Application:

<CFSETTING ENABLECFOUTPUTONLY="Yes">
<!--- Change this to your own datasource name --->
<CFSET dsn = "raffle">
<CFOUTPUT><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
     <title>Add raffle entry</title>
</head>

<body>
</CFOUTPUT>


<CFIF IsDefined('form.submit')>

  <CFTRANSACTION>
 
    <CFQUERY NAME="getUser" DATASOURCE="#dsn#">
      SELECT [User],[tickets]
      FROM raffle
      WHERE [user] = '#Trim(form.user)#'  
    </CFQUERY>
   
    <CFIF getUser.RecordCount>
   
      <CFQUERY DATASOURCE="#dsn#">
      UPDATE raffle
      SET
      tickets = #Evaluate(getUser.tickets + val(form.tickets))#
      WHERE [user] = '#trim(form.user)#'
      </CFQUERY>
     
    <CFELSE>
   
      <CFQUERY DATASOURCE="#dsn#">
      INSERT INTO raffle
      ([user], [tickets])
      VALUES
      ('#trim(form.user)#',#val(form.tickets)#)
      </CFQUERY>
   
    </CFIF>
   
    <CFQUERY NAME="GetResults" DATASOURCE="#dsn#">
    SELECT [user],[tickets]
    FROM raffle
    WHERE [user] = '#trim(form.user)#'
    </CFQUERY>
     
  </CFTRANSACTION>
 
  <CFOUTPUT>
  Successfully updated #form.user#.<BR>
  <BR>
  This user now has #GetResults.tickets# tickets.<BR>

  </CFOUTPUT>
 
 
<CFELSEIF IsDefined('url.action') AND NOT CompareNoCase(url.Action,'ShowAll')>

  <CFQUERY NAME="getAll" DATASOURCE="#dsn#">
    SELECT [user],[tickets]
    FROM raffle
    ORDER by tickets
  </CFQUERY>
  <CFOUTPUT>
  <TABLE>
  <TR>
  <TH>
  User
  </TH>
  <TH>
    Tickets
  </TH>
  </TR>
  <CFLOOP QUERY="getall">
    <TR>
      <TD>
        #getall.user#
      </TD>
      <TD>
        #getall.tickets#
      </TD>
    </TR>
  </CFLOOP>
  </TABLE>
  </CFOUTPUT>
 
 
<CFELSEIF IsDefined('url.action') AND NOT CompareNoCase(url.action,'drawraffle')>
 
  <CFQUERY NAME="GetTotal" DATASOURCE="#dsn#">
    SELECT sum(tickets) as total
    FROM raffle
  </CFQUERY>
 
 <CFQUERY NAME="getAll" DATASOURCE="#dsn#">
    SELECT [user],[tickets]
    FROM raffle
    ORDER by tickets
  </CFQUERY>

<!---  Now we have the total and the amount per person we need to use a weighted measure --->
<CFSET winnerspie = structnew()>
<CFSET lastStart = 0>
<CFLOOP QUERY="getAll">
<CFSET winnerspie[getall.user] = StructNew()>
<CFSET winnerspie[getall.user]['start'] = lastStart>
<CFSET winnerspie[getall.user]['end'] = lastStart + (getall.tickets/gettotal.total)*100>
<CFSET lastStart = winnerspie[getall.user]['end']>
</CFLOOP>

<CFSET winningnumber = Rand()*100>
<CFLOOP COLLECTION="#winnerspie#" ITEM="i">
  <CFIF winnerspie[i]['start'] LT winningnumber AND winnerspie[i]['end'] GT winningnumber>
   <CFOUTPUT> The winner is #i#</CFOUTPUT>
  </CFIF>
</CFLOOP>


<CFELSE>
<CFOUTPUT><FORM ACTION="#cgi.script_name#" METHOD="post">
<TABLE>
<TR>
<TD>
  User:
</TD>
<TD>
  <INPUT TYPE="Text" NAME="user">
</TD>
</TR>
<TR>
<TD>
Tickets to Add:
</TD>
<TD>
<INPUT TYPE="Text" NAME="tickets" SIZE="4">
</TD>
</TR>
<TR>
<TD COLSPAN="2" ALIGN="center">
<INPUT TYPE="Submit" NAME="Submit" VALUE="Add">
</TD>
</TR>
<TR>
<TD>
<A HREF="#cgi.script_name#?action=drawraffle">Draw raffle</A>
</TD>
<TD>
<A HREF="#cgi.script_name#?action=showall">show all users</A>
</TD>
</TR>
</TABLE>
</FORM>
</CFOUTPUT>


</CFIF>

<CFOUTPUT>
</body>
</html>
</CFOUTPUT>
<CFSETTING ENABLECFOUTPUTONLY="No">
<CFSETTING SHOWDEBUGOUTPUT="No">

Spike


0
 

Author Comment

by:hansamryan
ID: 6231685
WOW Thanks!! It works Great!! I had to add ?action= to the url when I call it though because it was looking for it but thats alright I will go through it, change that part later.
but besides that. it works perfect!!

Thanks,
Ryan Zimmerman
0
 

Author Comment

by:hansamryan
ID: 6231689
OOOpppsss I suppose I should accept it!!
0
 
LVL 4

Expert Comment

by:CF_Spike
ID: 6231699
you're welcome
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

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…
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

13 Experts available now in Live!

Get 1:1 Help Now