?
Solved

Complicated Question

Posted on 2001-06-26
4
Medium Priority
?
149 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
[X]
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
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
CF_Spike earned 800 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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