<?
include "base.php";
$table_name = superloto;
function state($first,$second,$table_name)
        {
        $rnd=rand(0,1000);
        if($rnd>=0&&$rnd<500){
   $win_amount = "0";
                return "lose";
                }
                else{
                $win=0;
                $lose=0;
                $sql="select STATE from $table_name order by ID";
                $res=mysql_query($sql);
                $num=mysql_num_rows($res);
                if($num!=0&&$num>=$second){
                        $num-=$second;
                        mysql_data_seek($res,$num);
                        while($row=mysql_fetch_array($res)){
                                if($row["STATE"]=="win"){
                                        $win++;
                                        }
                                        else{
   $win_amount = "0";
                                        $lose++;
                                        }
                                }
                        if($first<=$win){
                                $win_amount = "0";
                                return "lose";
                                }
                                else{
                                return "win";
                                }
                        }
                        else{
                        $win_amount = "0";
                        return "lose";
                        }
                }
        }
$win_state=state($first,$second,"superloto"); 

if ($win_state == lose) { $win_amount = "0"; }


?>