Solved

Complicated Question

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

Backup Your Microsoft Windows Server®

Backup 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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 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

16 Experts available now in Live!

Get 1:1 Help Now