Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.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 对于另一列中具有相同值的每个结果,如何将时间戳值增加1_Php_Mysql_Sql_Magento_Timestamp - Fatal编程技术网

Php 对于另一列中具有相同值的每个结果,如何将时间戳值增加1

Php 对于另一列中具有相同值的每个结果,如何将时间戳值增加1,php,mysql,sql,magento,timestamp,Php,Mysql,Sql,Magento,Timestamp,我正在使用自定义查询从Magento获取采购订单,如下所示: SELECT customer_id, UNIX_TIMESTAMP(o.created_at) as timestamp, increment_id as order_id .... joins here... SQL可以工作,但我需要使用数据导入第三方系统,当订单ID相同时,它们不接受相同的时间戳-建议的解决方案是对具有相同订单ID的每一行的时间戳执行+1 这甚至可以使用纯SQL实现吗?我需要跟踪顺序,以查看之前是否输出过,如果

我正在使用自定义查询从Magento获取采购订单,如下所示:

SELECT customer_id, UNIX_TIMESTAMP(o.created_at) as timestamp, increment_id as order_id .... joins here...
SQL可以工作,但我需要使用数据导入第三方系统,当订单ID相同时,它们不接受相同的时间戳-建议的解决方案是对具有相同订单ID的每一行的时间戳执行+1

这甚至可以使用纯SQL实现吗?我需要跟踪顺序,以查看之前是否输出过,如果是,则每次在时间戳值上加1

因此,假设我得到第一个结果,以订单123和时间戳45672作为示例数据,然后对于下一个结果,我得到相同的订单123,并且需要对时间戳=45673执行45672+1,具有相同订单的下一行应为45674,依此类推,直到订单id再次唯一,我可以使用实际值“.o.created_at”


任何建议,即使它需要PHP对结果进行操作?

也可以使用一些查询和临时表,但出于明显的原因,我不建议使用这种方法

不过,您可以通过PHP操作轻松地完成这项工作。只需确保结果按
时间戳排序
,以简化操作。例如:

$last_timestamp = 0;
while ($row = mysql_fetch_assoc($result))
{
    if ($row['timestamp'] <= $last_timestamp)
        $row['timestamp'] = $last_timestamp + 1;
    $last_timestamp = $row['timestamp'];

    // ... do stuff

}
$last\u timestamp=0;
while($row=mysql\u fetch\u assoc($result))
{
如果($row['timestamp']