Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在不同的表中插入相同的'datetime'变量?_Php_Codeigniter_Date_Datetime - Fatal编程技术网

Php 如何在不同的表中插入相同的'datetime'变量?

Php 如何在不同的表中插入相同的'datetime'变量?,php,codeigniter,date,datetime,Php,Codeigniter,Date,Datetime,我想使用两个函数将datetime变量存储到不同的表中。我在CI中使用了constraint,但仍然没有运气 这就是约束条件: $date_now = date("ymdhis"); define('TODAY_DATE',$date_now); 这些是功能: public function save_activity_m(){ foreach($details as $rows){ $stock_in = $rows['product

我想使用两个函数将
datetime
变量存储到不同的表中。我在
CI
中使用了
constraint
,但仍然没有运气

这就是约束条件:

$date_now = date("ymdhis");
define('TODAY_DATE',$date_now);
这些是功能:

public function save_activity_m(){
   foreach($details as $rows){          

      $stock_in          = $rows['product']."_".TODAY_DATE;
      $data['STOCK_IN']  = ($rows['product'] == "") ? NULL : $stock_in;

      $this->MProduct->ins_product_m($data);
   }
   echo "<script type='text/javascript'>alert('New stock arrived');window.top.location.reload();</script>";
}

public function save_notifikasi(){

    $lampiran = $this->input->post('lamp');     

    $data['note_date'] = $lampiran."_".TODAY_DATE;      
    $data['note']       = $this->input->post('isi');

    $this->MProduct->ins_notif($data);
     echo "<script type='text/javascript'>alert('You have a notification');</script>";


}
public function save_activity_m(){
foreach($详细信息为$行){
$stock_in=$rows['product']。“uu.”今天u日期;
$data['STOCK\U IN']=($rows['product']==”)?NULL:$STOCK\U IN;
$this->mpproduct->ins\u product\m($data);
}
echo“警报(‘新库存到达’);window.top.location.reload();”;
}
公共职能保存_notifikasi(){
$lampiran=$this->input->post('lamp');
$data['note_date']=$lampiran.“_.”今天_日期;
$data['note']=$this->input->post('isi');
$this->mpproduct->ins\u notif($data);
回显“警报('您有通知');”;
}

如何使日期时间与
$data['STOCK\u IN']
$data['note\u date']]
相同?

请参阅。这是一个常量,如果两个函数在脚本运行的同一时间执行,则其值应相同。

请参阅。这是一个常量,如果两个函数在脚本运行的同时执行,它的值应该相同。

由于web是无状态的,PHP变量中的任何数据都不会从一个页面(或加载)保存到另一个页面;实际上,每次都是从头开始启动应用程序

唯一的解决方法是使用某种半持久性存储,如cookie或会话变量(或数据库等持久性存储)——设置
常量,例如
define('TODAY\u DATE',$DATE\u now)仅在当前执行脚本时使该数据保持不变

这是一个使用会话存储的基本示例(
$\u session
):


由于web是无状态的,PHP变量中的任何数据都不会从一个页面(或加载)保存到另一个页面;实际上,每次都是从头开始启动应用程序

唯一的解决方法是使用某种半持久性存储,如cookie或会话变量(或数据库等持久性存储)——设置
常量,例如
define('TODAY\u DATE',$DATE\u now)仅在当前执行脚本时使该数据保持不变

这是一个使用会话存储的基本示例(
$\u session
):



我已经用过了。在秒数上是有区别的,可能是数据库的配置。行可以具有默认的当前\u时间戳或更新当前\u时间戳。也许吧?datetime的默认格式是:YYYY-MM-DD HH:MM:ss对不起,我是说varchar。这样做:$date\u now=date(“Y-m-d H:I:s”);我用过它。在秒数上是有区别的,可能是数据库的配置。行可以具有默认的当前\u时间戳或更新当前\u时间戳。也许吧?datetime的默认格式是:YYYY-MM-DD HH:MM:ss对不起,我是说varchar。这样做:$date\u now=date(“Y-m-d H:I:s”);您使用的是什么数据库服务器和数据类型?对于MySQL 5.7或MariaDB之类的东西,您需要使用一个
DATETIME
字段,日期的格式为
Y-m-d H:i:s
,您可以回显常量变量以检查它是否具有相同的值。我将DATETIME与表中的文本相结合。因此,我使用varcharYeah-抱歉,在扫描问题时忽略了这一点:|那么php中的日期时间必须相同您使用的是什么数据库服务器和数据类型?对于MySQL 5.7或MariaDB之类的东西,您需要使用一个
DATETIME
字段,日期的格式为
Y-m-d H:i:s
,您可以回显常量变量以检查它是否具有相同的值。我将DATETIME与表中的文本相结合。所以我使用varcharYeah-抱歉,在扫描问题时忽略了这一点:|因此php中的日期时间必须相同
<?php

// crank up the session
// you may well have one running already, 
// in which case ignore this
session_start();

// store the execution time for this script
// as a session variable if it's NOT already set
// i.e. don't overwrite it
if(empty($_SESSION['time_now'])) $_SESSION['time_now'] = date("ymdhis");


public function save_activity_m() {
    foreach($details as $rows) {          
        $stock_in = $rows['product'] . "_" . $_SESSION['time_now'];
        $data['STOCK_IN'] = ($rows['product'] == "") ? NULL : $stock_in;
        $this->MProduct->ins_product_m($data);
    }

    echo "<script type='text/javascript'>alert('New stock arrived');window.top.location.reload();</script>";
}

/**
 * Assuming this is the last thing you want to
 * do with 'time_now' you should unset it here
 */
public function save_notifikasi() {
    $lampiran = $this->input->post('lamp');     
    $data['note_date'] = $lampiran . "_" . $_SESSION['time_now'];
    $data['note'] = $this->input->post('isi');
    $this->MProduct->ins_notif($data);

    // since we're done with the 'time_now' session
    // variable we need to unset it...
    unset($_SESSION['time_now']);

    echo "<script type='text/javascript'>alert('You have a notification');</script>";
}

// just to be on the safe side unset the 'time_now' session var 
// if it's older than 1 minute - otherwise future calls to this 
// script, by the same user, during the same session will use 
// the stored value from $_SESSION['time_now']
if(isset($_SESSION['time_now'])) {
    $sessionTime = DateTime::createFromFormat('ymdhis', $_SESSION['time_now']);
    $oneMinuteAgoTime = new DateTime('-1 minute');

    if($sessionTime < $oneMinuteAgoTime) {
        unset($_SESSION['time_now']);
    }
}