Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Complicated Question

Posted on 2001-06-26
4
146 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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