0

私は他の誰かのコードで作業していて、簡単な追加をしようとしています。mySQL データベースにいくつかのデータがあります。列の 1 つは time_end で、これは将来の日付に設定されています。その日付が過ぎたら、特定のテキストを表示したい。

$events = get_all_events();

include 'templates/bet.php';

function get_all_events() {
global $_DB;

$stm = $_DB->prepare('select wl_bet.*, wl_group.gname, (select count(*) from wl_betplace where wl_betplace.betid = wl_bet.id) as countBet from wl_bet, wl_group where wl_bet.groupid = wl_group.gid order by time_end asc');
$stm->execute();
$data = $stm->fetchAll();

$close = array();
$active = array();
$paid = array();

$p = 0;
$c = 0;
$a = 0;
foreach ($data as $d) {
    if ($d['status'] == 2) {
        if ($p < 5) {
            array_push($paid, $d);
            $p++;
        }
    }
    else {
        if ($d['time_end'] < time()) {
            if ($c < 5) {
                array_push($close, $d);
                $c++;
            }
        }
        else {
            if ($a < 8) {
                array_push($active, $d);
                $a++;
            }
        }
    }
}
return array('close' => $close, 'active' => $active, 'paid' => $paid);
}

現在の日付が time_end の日付を過ぎている場合に表示するテーブルを次に示します。これはifステートメントと同じくらい単純であるべきだとわかっていますが、正しく理解できないようです。ここでも、現在の日付が mysql データベースの日付 (time_end) より大きくなったら、このテーブルを表示するだけです。

 <table width="100%" class="list-details sortable">

                <tr class="tablebar">
                    <th><div>Title</div></th>
                    <th><div>Event Date</div></th>
                    <th><div># of Bets</div></th>
                </tr>
                <?php foreach ($events['close'] as $c) : ?>
                <tr class="row">
                    <td><a href="?cmd=view-bet&id=<?php echo $c['id']; ?>"><?php echo $c['title']; ?></a></td>
                    <td><?php echo format_date_only($c['time_end']); ?></td>
                    <td><?php echo $c['countBet']; ?></td>
                </tr>
                <?php endforeach; ?>
            </table>
4

1 に答える 1

0

もちろん、これを投稿してから5分後、私はそれを理解します

<?php if(count($events['close']) > 0):?> text to show <?php endif; ?>
于 2012-10-15T20:30:43.973 に答える