1

朋友们,我决定创建一个以 PostgreSQL 作为后端的 PHP 程序。在此,我想创建一个页面,该页面显示一些时间表(时间表),并且用户必须使用单选按钮从中选择一个选项。我需要将“选择的时间 - 15分钟”传递给数据库中的某个字段。我使用的技术如下所示

     $a=$dt[$m].' '.$ftime;
     for($j=1;$j<=$slots;$j++)
    {   
    echo "<td>";
    if($j==1)
    {   
    $a= date("Y-m-d H:i:s", strtotime("$a + 0 minutes"));
    $value= date("Y-m-d^H:i:s", strtotime("$a + 0 minutes"));
    }
    else
    {
    $a= date("Y-m-d H:i:s", strtotime("$a + $intl minutes"));
    $value= date("Y-m-d^H:i:s", strtotime("$a + $intl minutes"));   
    }  
    $b=explode(" ",$a);  
    if(!in_array($a,$res_tm))   
    echo "<input type='radio' name='radio1' value=$value> $b[1]";
    else echo "Reserved";

我已经使用表单标签在另一个页面中完成了数据库操作。但问题是我想存储正确的值。但在此,我得到的值始终是所选值的增量$intl(即 15 分钟)。但我想传递正确的值。我发现值$value总是$intl比实际值大几分钟,但我无法纠正..任何人都请帮助我

4

1 回答 1

1

我认为这是因为您在“else”部分中的 $intl 从 2 而不是 1 开始。每次通过“else”部分时,尝试从中减去 1(或 15)。

if($j==1)
{   
   // Here you want $intl == 0, which is $j - 1.
   // Actually, you can drop the '+ 0 minutes' altogether
   $a= date("Y-m-d H:i:s", strtotime("$a"));
   $value= date("Y-m-d^H:i:s", strtotime("$a"));
}
else
{
   // I am guessing here, since I don't know the contents of $intl or $j.
   // You probably need either $intl - 1 or $j - 1.
   $intl_adjusted = $intl - 1;
   $a= date("Y-m-d H:i:s", strtotime("$a + $intl_adjusted minutes"));
   $value= date("Y-m-d^H:i:s", strtotime("$a + $intl_adjusted minutes"));   
}  
于 2013-08-14T08:55:16.600 回答