php中的时区循环问题

php中的时区循环问题,php,mysql,loops,timezone,Php,Mysql,Loops,Timezone,下面的代码创建一个循环,根据时间对循环进行排序,然后回显该循环的结果,直到没有更多的时间进行循环,然后停止循环 代码工作得很好,除了我似乎无法根据用户时区调整时间。当我尝试时,它似乎只显示一个结果,然后循环停止 while ( $row = $stmt->fetch() ) { if (!($sc > $stopcount)) { $i++; if( date('M d, Y', strtotime($row['time'])) !

下面的代码创建一个循环,根据时间对循环进行排序,然后回显该循环的结果,直到没有更多的时间进行循环,然后停止循环

代码工作得很好,除了我似乎无法根据用户时区调整时间。当我尝试时,它似乎只显示一个结果,然后循环停止

while ( $row = $stmt->fetch() ) 
{
    if (!($sc > $stopcount)) 
    {
        $i++;
        if( date('M d, Y', strtotime($row['time'])) !== $lastTime )
        { 
            if ($i == '1') 
            { 
                    echo '</tr><tr><td colspan="6" class="heading">'. date('M d, Y', strtotime($row['time'])) .'</td></tr>';
            } else if ( $lastTime === NULL ) 
            {
            echo '</tr>'; 
            } else 
            { echo '</tr><tr><td colspan="6" class="heading">'. date('M d, Y', strtotime($row['time'])) .'</td></tr>'; 
            }
            $lastTime = date('M d, Y', strtotime($row['time']));
        } if ($i >= $sc) 
        { ?>
            <tr>
                <td>
                    <input type="checkbox" name="checkbox" value="<? echo $row['id']; ?>" />
                </td>
                <td class="status">
                    <? if ($row['status'] == 'unopened' || $row['status'] == 'closed') { ?> 
                        <span id="<? echo $row['id']; ?>" class="icon-folder-close"></span> 
                    <? } ?>
                    <? if ($row['status'] == 'opened' || $row['status'] == 'reopened') { ?> 
                        <span class="icon-folder-open"></span> 
                    <? } ?>
                </td>
                <td>
                    <? echo $row['mailfrom']; ?>
                </td>
                <td>
                    <strong><a href="#preview_mail" class="mails_show open" id="<? echo $row['id']; ?>" data-toggle="modal" data-show="mail-<? echo $i; ?>"><? echo $row['subject']; ?></a></strong>
                    <div id="mail-<? echo $i; ?>" class="mails_container">
                        <div class="from"><? echo $row['mailfrom']; ?></div>
                        <div class="to"><? echo $row['mailto']; ?></div>
                        <div class="ids"><? echo $row['id']; ?></div>
                        <div class="key"><? echo $row['pin']; ?></div>
                        <div class="subject"><? echo $row['subject']; ?></div>
                        <div class="attach"><? if ($row['attachment'] !== NULL) { ?> <span class="icon-gift"></span> <a href="<? echo $row['attachment']; ?>"><? echo $row['attachment']; ?></a> <? } else { ?><span class="icon-none"></span>NONE<? } ?></div>
                        <div class="body">
                            <p><? echo $row['message']; ?></p>
                        </div>
                        <div class="body_reply">
                            <p><? echo $row['message']; ?></p>
                        </div>
                    </div>                                    
                </td>
                <td>
                    <?
                    $tttime = $row['time'];
                    $ttime = new DateTime($tttime);
                    $stmt=$db->prepare('SELECT timezone FROM member_credits WHERE username = :user');
                    $stmt->bindParam(':user', $username);
                    $stmt->execute();
                    $row1 = $stmt->fetch();
                    $usersTimezone = (new DateTimeZone($row1[timezone]));
                    $ttime->setTimeZone($usersTimezone);
                    $ttimee = $ttime->format('h:i, A');
                    ?>
                    <? echo $ttimee; ?>
                </td>
                <td style="padding: 10px 10px !important;">
                    <? if (isset($row[attachment])) { ?>
                        <span style="margin-left: 0 !important;" class="icon-gift"></span>
                    <? $bytes=filesize($row[attachment]); echo formatSizeUnits($bytes); } else {?> <? } ?>
                </td>
            </tr>
        <? $sc++;
        }  
    }
}
?>

我做错了什么?我怎么能这样写呢?时间是根据存储在数据库中的完整服务器日期/时间排序的,然后根据从用户时区设置转换而来的12小时格式(不带日期)的时间进行回显?

这花了我大量的时间

问题如下:

我有一个循环

while ( $row = $stmt->fetch() ) 
这意味着如果我将$row设置为$stmt->fetch()以外的其他值,while循环将结束。我从一开始就知道这一点,因此称第二个$row1

我没有意识到的是,这意味着如果我使用$stmt在while循环中执行其他函数,它将打破while循环

解决方案就是在时间函数中使用不同的变量

    $ttime = new DateTime($tttime);

    $stmt2=$db->prepare('SELECT timezone FROM member_credits WHERE username = :user');
    $stmt2->bindParam(':user', $username);
    $stmt2->execute();
    $row1 = $stmt2->fetch();

    $usersTimezone = (new DateTimeZone($row1[timezone]));
    $ttime->setTimeZone($usersTimezone);
    $ttimee = $ttime->format('h:i, A');

我花了很长时间才完成

问题如下:

我有一个循环

while ( $row = $stmt->fetch() ) 
这意味着如果我将$row设置为$stmt->fetch()以外的其他值,while循环将结束。我从一开始就知道这一点,因此称第二个$row1

我没有意识到的是,这意味着如果我使用$stmt在while循环中执行其他函数,它将打破while循环

解决方案就是在时间函数中使用不同的变量

    $ttime = new DateTime($tttime);

    $stmt2=$db->prepare('SELECT timezone FROM member_credits WHERE username = :user');
    $stmt2->bindParam(':user', $username);
    $stmt2->execute();
    $row1 = $stmt2->fetch();

    $usersTimezone = (new DateTimeZone($row1[timezone]));
    $ttime->setTimeZone($usersTimezone);
    $ttimee = $ttime->format('h:i, A');