-- No php required, just mysql. No crazy rowcounts just 12 in this example.
create table rg
( -- RaffleGuy
guyId int auto_increment primary key,
fullName varchar(100) not null,
cellPhone varchar(20) not null,
ticketCount int not null,
winLow int null,
winHigh int null
);
-- trucate table rg; -- for testing next time
insert rg (fullName,cellPhone,ticketCount) values ('johnny two thumbs','11111',126);
insert rg (fullName,cellPhone,ticketCount) values ('kim','153111',500);
insert rg (fullName,cellPhone,ticketCount) values ('Lady with Hat','113211',1);
insert rg (fullName,cellPhone,ticketCount) values ('Guy with Nose','14454111',900);
insert rg (fullName,cellPhone,ticketCount) values ('Kipper','2211111',100);
insert rg (fullName,cellPhone,ticketCount) values ('Jipper','222888',400);
insert rg (fullName,cellPhone,ticketCount) values ('smith family','534511111',500);
insert rg (fullName,cellPhone,ticketCount) values ('First Pentacostal Church','3153111',200);
insert rg (fullName,cellPhone,ticketCount) values ('Lady with Hat','1132141',123);
insert rg (fullName,cellPhone,ticketCount) values ('Guy with Nose','14441311',500);
insert rg (fullName,cellPhone,ticketCount) values ('Kipper','2211711',300);
insert rg (fullName,cellPhone,ticketCount) values ('Jipper','2272',200);
update rg
join
(select rg.guyId,(select ifnull(sum(ticketCount)+1,1) from rg r2 where r2.guyId<rg.guyId) below
from rg) nnn
on nnn.guyId=rg.guyId
set winLow=nnn.below,winHigh=nnn.below+ticketCount-1
select * from rg;
# fullName cell# tix wLow wHigh
1 johnny two thumbs 11111 126 1 126
2 kim 153111 500 127 626
3 Lady with Hat 113211 1 627 627
4 Guy with Nose 14454111 900 628 1527
5 Kipper 2211111 100 1528 1627
6 Jipper 222888 400 1628 2027
7 smith family 534511111 500 2028 2527
8 First Pentacostal Church 3153111 200 2528 2727
9 Lady with Hat 1132141 123 2728 2850
10 Guy with Nose 14441311 500 2851 3350
11 Kipper 2211711 300 3351 3650
12 Jipper 2272 200 3651 3850
select sum(ticketCount) into @tottix from rg; -- 3850
-- seed your random number, I leave that to you
select rand(unix_timestamp()); -- example
select floor(rand()*@tottix)+1 into @thernd; -- 531
select * from rg where winLow<=@thernd and winHigh>=@thernd;
2 kim 153111 500 127 626
Kim wins, call her