View Single Post
  #1 (permalink)  
Old 02-18-2008, 03:34 PM
shaunlevett shaunlevett is offline
Member
 
Join Date: Nov 2007
Posts: 30
Red face issues with php survey

Hi guys I wonder if you can help. Basically I'm creating a business to business survey for my employer. My php knowledge is only low level and I'm having an issue I'm not sure how to remedy.

Once you enter the survey and your details, the "id" field in the database auto increments by one. And once the survey is completed the below code will divide the id by five (one in five win chance), and if its an integer they win a prize (digital photo frame). Simple enough, they either win a prize or not with a 1in5 chance. But now my boss wants me to include a second prize, but still a 1in5 chance to win.


$win = $id / 5;


if (preg_match ("/^\d+$/", $win))
{
$winner="Winner";
$messagecode = 22;
}
else {
$winner="no win";
$messagecode = 1983;
}
if ($winner == "Winner"){ $printwin ="Digital Photo Frame WINNER!";} else {$printwin ="No Winner.";}


The problem is my code will only detect the 1 in 5 chance then tell them they've won the photo frame, I'm not sure how to include a second possible prize. What I thought of doing was finding the total amount of people who are going to survey (say 8000) then saying:

if id is an integer & less than 4000, win a camera
if id is an integer & more than 4000, win a digital frame
if not an integer, no win.

I think this would solve my multiple prize problem, but I'm not sure of the syntax. Could any of you kind souls help a brother out?
Reply With Quote