结果PHP Mysql之间的间距

时间:2016-05-28 07:38:51

标签: php mysql

我有以下代码。

我对PHP和mysql来说是全新的

<table align="center" border="0" width="100%">
<tr>
<th>id</th>
    <th>Staff Name</th>
    <th>Date</th>
    <th>Reason</th>
</tr>

<?php

    $startdate = $_SESSION['startdate'];
    $enddate = $_SESSION['enddate'];

    $code = mysql_query("SELECT id, name, UNIX_TIMESTAMP(date) AS date, reason FROM taken WHERE date BETWEEN '$startdate' AND '$enddate' ORDER BY date ASC");


    while($row = mysql_fetch_array($code)) {



 echo "\t<tr><td>{$row['id']} ".
"</td><td>{$row['name']}  ".
"</td><td>" . date( "d/m/Y", $row['date'] ) ."".
     "</td><td>{$row['reason']} </td></tr>\n";

它产生以下结果但我想在日期更改之间放置一个空格。 I.E 2016年5月28日之间的空间/休息时间29/05/26

任何帮助将不胜感激。

id  Staff Name  Date    Reason
1296    28/05/2016  Holiday
1832    28/05/2016  Holiday
1330    28/05/2016  Holiday
825 28/05/2016  Holiday
1858    28/05/2016  Holiday
849 28/05/2016  Holiday
1958    28/05/2016  Holiday
2022    28/05/2016  Holiday
1263    28/05/2016  Holiday
1331    29/05/2016  Holiday
826 29/05/2016  Holiday
1959    29/05/2016  Holiday
2023    29/05/2016  Holiday
1264    29/05/2016  Holiday
1332    30/05/2016  Holiday
827 30/05/2016  Holiday
1960    30/05/2016  Holiday
2024    30/05/2016  Holiday
1265    30/05/2016  Holiday
533 31/05/2016  Holiday
1843    31/05/2016  Holiday
52  31/05/2016  Holiday
1420    31/05/2016  Holiday
1679    31/05/2016  Holiday
1938    31/05/2016  Holiday
936 31/05/2016  Holiday
231 31/05/2016  Holiday

1 个答案:

答案 0 :(得分:0)

代码通过添加空行

来添加空间
$save = null;
while($row = mysql_fetch_array($code)) {
   $date = date( "d/m/Y", $row['date'];
   if ($save && $date != $save) {
      $save = $date;
      echo "\t<tr><td cplspan="4">&nbsp;</td></tr>\n"
   } 
   echo "\t<tr><td>{$row['id']} ".
        "</td><td>{$row['name']}  ".
        "</td><td>$date</td><td>{$row['reason']} </td></tr>\n";
}