遍历数组并回显下一个事件

时间:2018-08-20 19:46:26

标签: php mysql sql

我将事件存储在mysql中,并使用php进行了检索。我检索月,日和年,然后将其添加到数组中。有没有办法遍历该数组并获取下一个即将发生的事件?

$array = [''];
$result = mysqli_query($con,"SELECT * FROM events") or die ("couldn't fetch query");

// output data of each row
while($row = mysqli_fetch_array($result)) {
    $date = $row['eMonth'] . "-" . $row['eDay'] . "-" . $row['eYear'];
    array_push($array, $date);
}

1 个答案:

答案 0 :(得分:0)

为每个事件创建一个日期列,并使用此查询从当前日期中选择接下来的3个事件

import pandas as pd

df = pd.read_csv(filename)


df_initial = df.loc[df['LetterStatus']=='CLOSED']
dfx = df.loc[df['LetterStatus']=='UPDATED']


df_merged = pd.merge(df_initial,dfx,how='left',left_on='ReferenceNumber',right_on='ReplacedByRefNumber')
df_copy = df_merged
for row in range(len(df_merged)):
    if  len(str(df_merged.iloc[row]['ReplacedByRefNumber_y'])) > 1:
        row_slice = dfx.iloc[['ReferenceNumber']==df_merged[row['ReplacedByRefNumber_y']]
        if row_slice.size == 0:
            df_merged.iloc[row]['ReplacedByRefNumber_y']='Unknown'
            df_copy.iloc[row]['ReplacedByRefNumber_y']='Unknown'
        else:
            df_copy.iloc[row][24:0]=row_slice


print(df_copy)