0

我有一张人的表格,以及他们在 2005 年至 2010 年间居住的地方:

 Person     Address          From_dt       To_dt           PersonRow
------     -------          ------        -----           ---------
1          known            2005-01-01    2010-12-31      1
2          known            2006-01-01    2007-01-01      1

但是我想为第 2 个人添加两行,所以我的表格变成:

Person     Address          From_dt       To_dt           PersonRow
------     -------          ------        -----           ---------
1          known            2005-01-01    2010-12-31      1
2          unknown          2005-01-01    2005-12-31      1
2          known            2006-01-01    2007-01-01      2
2          unknown          2007-01-02    2010-12-31      3

为第 2 个人填写 2005-2010 年之间的空白。即使他们有多个居住地,也必须填写空白。我想我对正确的日期不太感兴趣(注意如何从其他居住日期获得推算日期对于同一个人),因为我已经得到了帮助。

非常感谢。

4

1 回答 1

0

您可以选择行,然后在 while 循环中执行以下操作:

$prevRow = array();
while($fetch = mysql_fetch_assoc($select) ){
    if(count($prevRow)===0){ // first round of loop it has 0 values, so nothing to match
        if($prevRow['To_dt'] !== $fetch['From_dt']){ // check the two rows' dates
            // Please note! This will not work. You will need to add 1 day to the first, or subtract 1 day from the 2nd value!
            // Insert a row "unknown" with the two values from the above if-statement
        }
    }
    $prevRow = $fetch;// save so next round we can compare
}
于 2013-06-25T13:10:32.097 回答