Infinite loop in PHP -


i working on project have random planning of 144 lawyers. planning per month.so on every day of month have 3-4 lawyers. planning made @ beginning on every month. planning must random , every people picked-up equally.

my idea this: first time picked 4 people each day([144/31]=4) , remaining 20 planned on 01-20 may. there 4 plans , every lawyer choose on plan participate. in database store in table every option. example, if opts plan 1 ( called politie_parchet_all), have 1 in table database).

the problem here ...this code run if clause,and remaining 24 people remain non-selected.i think don't exit if clause , don't know why?

$str_date ="01-".$luna."-".$an; $start_date = strtotime($str_date); $end_date = strtotime('+1 month',$start_date);  $number_days = date("t",$start_date); $nr_lawyer =number_lawyer($planificare);     while ($nr_lawyer >0)  {     $nr_lawyer =number_lawyer($planificare);     if($nr_lawyer > $number_days)     {         $nr = intval($nr_lawyer/$number_days);          while ($start_date < $end_date)          {             $time=date('y-m-d',$start_date);              ($i=1; $i<=$nr; $i++)             {                  $time=date('y-m-d',$start_date);                 selectare_avocat($planificare,$time);             }             $start_date = strtotime('+1 days',$start_date);         }     }     else if($nr_lawyer < $number_days)     {         $str_date ="01-".$luna."-".$an;          $start_date = strtotime($str_date);         $end_date = strtotime('+'.number_lawyer($planificare).' days',$start_date);         echo date('y-m-d',$end_date);         while ($start_date < $end_date)          {             $time=date('y-m-d',$start_date);             selectare_avocat($planificare,$time);             $start_date = strtotime('+1 days',$start_date);         }     }     $nr_lawyer = number_lawyer($planificare); } 

selectare_avocat function select random lawyer, store random lawyer in generare_liste table , update select = 1

select = 0 means can selected. if lawyer selected not selected again until lawyers have been picked up.

selectare_avocat() function : <- function work well.

function selectare_avocat($planificare,$time) {     global $con;     $sql3="select avocat.id avocat  avocat.select=0 , avocat.".$planificare." = 1 , avocat.id not in (select id_avocat generare_liste `data` '{$time}') order rand() limit 1";     $result3 = mysqli_query($con,$sql3);     $row=mysqli_fetch_array($result3);     $id = $row['id'];      $sql4="insert generare_liste(id,id_avocat,planificare,data)values(null,".$id.",'{$planificare}','{$time}')";     mysqli_query($con,$sql4);     $sql2="update `avocat` set `select`=1 id={$id}";     mysqli_query($con,$sql2); } 

the problem script never ends , remains blocked on if clause (because after running have 124 lawyers in generare_lista table) , remaining 20 lawyers must picked else clause.

my suggestion is:

get count of day in actual month => $number_days = date("t",$start_date); initialize variable $cont = 1; create empty array $list = array(); loop in array of data until it's empty; $list[$cont] = random value array data, remove array data; test if $cont greater $number_days, turn 1 increment $cont++;

this routine fits count of lawyers.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -