Solved

Complicated Question

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

14 Experts available now in Live!

Get 1:1 Help Now