English 中文(简体)
• 如何使产生PHP代码的过程自动化?
原标题:How to automate the process to generate PHP code?
  • 时间:2011-06-06 11:24:28
  •  标签:
  • php

我有这个项目,我不得不每星期天产生一套新的“临时”计划。 现在,有用户的Im通过从星期天开始投入手工操作,然后用我的文字填写到下星期六(例如:用户填充“从[6月]的[第5段]的基因转变”,然后它便产生从6月的第5(sun)到第11(sat)的转变。

Shift generation:

function generateShifts($day_start, $month, $year)
{
    global $months, $month_lengths, $days, $times, $positions;
    $f = 0;
    $day = $day_start;
    for($i = $day_start; $i < ($day_start + 7); $i++)
    {
        if($day > $months[$month-1]["length"]) //are we entering a new month?
        {
            $day = 1;
            $month++;
        }
        if($month > 12) //are we entering a new year?
        {
            $month = 1;
            $year++;
        }
        for($p = 0; $p < count($positions); $p++)
        {
            for($t = 0; $t < count($times); $t++)
                $sql = mysql_query("INSERT INTO `shifts` (position, day, month, year, time, full_day) VALUES ( ". $positions[$p] ." ,  ". $day ." ,  ". $month ." ,  ". $year ." ,  ". $times[$t] ." ,  ". $days[$f] ." )");
        }
        $f++;
        $day++;
    }
} 

这些转变具有某些特性,如位置、日、月、年、时间(例如:6AM-4PM等)和独一无二的身份证。 日、月和年数是D-M-YY格式(例如:6-6-11)。 我有各种阵列,其名称很短,如Jun、Jul、Aug等。 (第6个月,I d 每月美元——姓名[月值]-1](-1,因为阵列的起点当然是指数0),而我会获得“Jun”。

Now I want to automate this process so a new week of shifts is generated automatically every Sunday. I can t use a cron job if that is an option at all. It needs to be pure HTML/JS/PHP.

我不要求完整的文字,而只是要求正确方向。

问题回答

除非你离开你的浏览器整周运行,否则你就能够自动这样做。 或者说,你可以把这部法典放在某个地方,这样用户就可以在没有知情的情况下加以执行(如果你需要用这种方法更新这些清单,不会忘记增加检查)。

此外,你还可以寻找“按时工作”的APICES供应商(现场将按预期时间使用你的文字)。

如果我正确理解你的话,你就只需要每周一次的这项职能,但这一职能的结果不会改变。

我可以看到多种解决办法(打破僵局):

  • either you enforce an admin to do it once a week, else you get an application failure
  • or (as advised by Valdas in the meantime, sorry for the double answer here) you do it transparently somewhere in an include file (quick & dirty solution, will certainly fail at some point)
  • or (best solution IMHO), you just generate in advance the shifts for the year to come.

你可以在你的法典中创造某种信念。

  1. Check to see if the job has been run on each page load for this week.
  2. If it hasn t, then run the function provided

检查每页负荷的间接费用(可能微不足道)和工作管理费用(每页一次)。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签