通过PHP进行的Bootstrap面板对日期进行排序



我正在构建php mysql应用程序进行工作面试,我想使用带有bootstrap面板的admin filer,这些filer在同一颜色列中按日期进行排序。

$db = connectPDO();
   $query = ("SELECT razgovori.*, djelatnik.ime, djelatnik.prezime
        FROM razgovori INNER JOIN djelatnik 
        ON djelatnik.id = razgovori.insert_by 
        ORDER BY datum_raz ASC");
  $stmt = $db->prepare($query);
  $stmt->execute();
  $count = $stmt->rowCount();
  $row = $stmt->fetch(PDO::FETCH_ASSOC);
  $date = strtotime($row['datum_raz']);
  $twoDaysAgoStart =  strtotime('-2 day 00:00:00');
  $yesterdayEnd =  strtotime('yesterday 23:59:59');
  $todayStart = strtotime('today 00:00:00');    
  $todayEnd = strtotime('today 23:59:59');  
  $tomorrowStart =  strtotime('tomorrow 00:00:00'); 
  $twoDaysAheadEnd =  strtotime('+2 day 23:59:59');
   <div class="container">
  <div class="row">
    <?php while ($row = $stmt->fetch(PDO::FETCH_ASSOC)): ?>
     <?php $date = strtotime($row['datum_raz']); ?>   
    <?php if ($twoDaysAgoStart < $date && $yesterdayEnd > $date): ?> 
  <!--Panel info if past time Job interviews-->
  <div class="col-md-4 pull-left">
   <div class="panel panel-info">
    <div class="panel-heading"><h3 class="panel-title"><?php echo 
     datumVrijemeSQLuHR($row['datum_raz']); ?></h3></div>
    <div class="panel-body">
      <div class="col-md-9">
        <h5><a href="editRazgovori.php?id=<?php echo $row['id']; ?>"><?php 
         echo $row['rime'].' '.$row['rprezime']; ?></a></h5>           
          <?php echo $row['kontakt_br']; ?>
      </div>
      <div class="col-md-3">
        <span class="label label-default pull-right"></h5><?php echo 
    $row['ime'].' '.$row['prezime']; ?></span>
      </div>
    </div>
  </div>      
</div>
<!--//Panel--> 
</tr>
<tr>
<!--Panel primary if Job interview is today-->
<?php elseif ($todayStart <= $date && $todayEnd >= $date): ?>  
 <div class="col-md-4">
  <div class="panel panel-primary">
    <div class="panel-heading"><h3 class="panel-title"><?php echo 
datumVrijemeSQLuHR($row['datum_raz']); ?></h3></div>
    <div class="panel-body">
   <div class="col-md-9">
    <h5><a href="editRazgovori.php?id=<?php echo $row['id']; ?>"><?php echo 
$row['rime'].' '.$row['rprezime']; ?></a></h5>           
        <?php echo $row['kontakt_br']; ?>
      </div>
        <div class="col-md-3">
            <span class="label label-default pull-right"></h5><?php echo 
$row['ime'].' '.$row['prezime']; ?></span>
          </div>
    </div>
  </div>      
</div>
</tr>
<tr>
<!--Panel warning if Job interview is tomorrow-->
<?php  elseif ($tomorrowStart <= $date && $twoDaysAheadEnd >= $date): ?>   
 <div class="col-md-4 pull-right">
  <div class="panel panel-warning">
    <div class="panel-heading"><h3 class="panel-title"><?php echo 
        datumVrijemeSQLuHR($row['datum_raz']); ?></h3></div>
    <div class="panel-body">
      <div class="col-md-9">
      <h5><a href="editRazgovori.php?id=<?php echo $row['id']; ?>"><?php 
        echo $row['rime'].' '.$row['rprezime']; ?></a></h5>           
          <?php echo $row['kontakt_br']; ?>
        </div>
          <div class="col-md-3">
              <span class="label label-default pull-right"></h5><?php echo 
                      $row['ime'].' '.$row['prezime']; ?></span>
            </div>
        </div>
      </div>      
      </div>
     <?php endif; ?>

    <?php endwhile; ?> 
  </div><!--/row-->
</div><!--/container-->

我想像主套件一样排序或没有

我得到了这个:在此处输入图像描述

因为stackoverflow红色消息不断要求我提供更多详细信息,所以我不能放置所有PHP代码

您可以在MySQL查询中执行此操作。

示例:

SELECT * FROM t1
  ORDER BY key_part1, key_part2;
SELECT * FROM t1
  WHERE key_part1 = constant
  ORDER BY key_part2;
SELECT * FROM t1
  ORDER BY key_part1 DESC, key_part2 DESC;
SELECT * FROM t1
  WHERE key_part1 = 1
  ORDER BY key_part1 DESC, key_part2 DESC;
SELECT * FROM t1
  WHERE key_part1 > constant
  ORDER BY key_part1 ASC;
SELECT * FROM t1
  WHERE key_part1 < constant
  ORDER BY key_part1 DESC;
SELECT * FROM t1
  WHERE key_part1 = constant1 AND key_part2 > constant2
  ORDER BY key_part2;

更多信息可以在此处找到:https://dev.mysql.com/doc/refman/5.7/en/order-order-by-by-optimization.html或https://wwwww.w3schools.com/sql/sql_orderbyby。asp

如果您想在PHP内部执行此操作,则可以使用Sort:

<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
    echo "fruits[" . $key . "] = " . $val . "n";
}
?>

上面的示例将输出:

水果[0] =苹果水果[1] =香蕉水果[2] =柠檬水果[3] = 橙色

有关PHP sort()的更多信息:http://php.net/manual/en/function.sort.php

相关内容

  • 没有找到相关文章

最新更新