如果某个单元格包含X,PHP会从TSV文件中跳过整行

时间:2014-01-30 21:16:17

标签: php

我有一个脚本从TSV文件中提取数据,然后以表格格式将其显示给用户,它还会在echo之后将结果插入数据库。我被问到是否可以添加#rule,如果例如$ organizer等于“黑名单”中列出的组织者,则整行被跳过而不显示在屏幕上,也不会插入到数据库中。我前一段时间尝试做一个while循环,但是我打破了现有的循环,所以我不得不恢复原状。如果该行中的值包含某个值,我将如何“跳过”一行。

<?php
  $rs=odbc_exec($conn,$excel);
  while($row = odbc_fetch_array($rs)) 
{
$TimeStamp=odbc_result($rs,"TimeStamp");
$Start_Date=odbc_result($rs,"StartDate");
$TimeStamp = new DateTime($TimeStamp);
$TimeStamp_date = $TimeStamp->format('Y-m-d');
$TimeStamp_time = $TimeStamp->format('h:i:s');

if ($TimeStamp_date == $today)
{
    if ($Start_Date == $today)
    {
    $ID=odbc_result($rs,"ID");
    $StartDate=odbc_result($rs,"StartDate");
    $StartTime=odbc_result($rs,"StartTime");
    $Organizer=odbc_result($rs,"Organizer");
    $MeetingSubject=odbc_result($rs,"MeetingSubject");

    echo '
    <tr>
        <td class="td" valign="top">' . $StartDate . '</td>
        <td class="td" valign="top">' . $StartTime . '</td>
        <td class="td" valign="top">' . $Organizer . '</td>
        <td class="td" valign="top">' . $MeetingSubject . '</td>             </tr> ';
    }
}
}
?>

1 个答案:

答案 0 :(得分:1)

如果插入代码的其余部分在while内,这应该可以。

<?php
$rs=odbc_exec($conn,$excel);
while($row = odbc_fetch_array($rs)) 
{

    if($whateverrowvalue != "blacklistvalue") {

        $TimeStamp=odbc_result($rs,"TimeStamp");
        $Start_Date=odbc_result($rs,"StartDate");
        $TimeStamp = new DateTime($TimeStamp);
        $TimeStamp_date = $TimeStamp->format('Y-m-d');
        $TimeStamp_time = $TimeStamp->format('h:i:s');

        if ($TimeStamp_date == $today)
        {

            if ($Start_Date == $today)
            {
            $ID=odbc_result($rs,"ID");
            $StartDate=odbc_result($rs,"StartDate");
            $StartTime=odbc_result($rs,"StartTime");
            $Organizer=odbc_result($rs,"Organizer");
            $MeetingSubject=odbc_result($rs,"MeetingSubject");

            echo '<tr>
            <td class="td" valign="top">' . $StartDate . '</td>
            <td class="td" valign="top">' . $StartTime . '</td>
            <td class="td" valign="top">' . $Organizer . '</td>
            <td class="td" valign="top">' . $MeetingSubject . '</td></tr> ';
            }   

        }

    }

}
?>