-2

HTMLページに今後の日付を表示するクエリがあります。日付を dd/mm/yyyy として表示しようとしています。完全なコードは以下のとおりです。「date1」は表示したい日付です。

<?php
$con=mysqli_connect("localhost","root","","mentertraining");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }


$query = "SELECT `coursedates`.`coursedate_id`,`courses`.`course_title`,`courses`.`no_of_days`,`category`.`category_name`,`coursedates`.`date1` FROM coursedates "
    . " LEFT JOIN `mentertraining`.`courses` ON `coursedates`.`course_id` = `courses`.`course_id` "
    . " LEFT JOIN `mentertraining`.`category` ON `courses`.`category_id` = `category`.`category_id` LIMIT 0, 5 ";

$result = mysqli_query($con,$query);
    echo "<table cellspacing='1'><tr bgcolor='#fe0075'><th>Course Title</th><th>Course Date</th></tr>";

while($row    = mysqli_fetch_assoc($result))
  {
  echo "<tr>";
  echo "<td>" . $row['course_title'] . "</td>";
  echo "<td>" . $row['date1'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysqli_close($con);
?>

助けてくれてありがとう

4

3 に答える 3

1

日付が文字列形式の場合、次date functionのように使用できますecho date('d/m/Y', strtotime($row['date1']);

于 2013-06-30T17:07:24.077 に答える
0
while($row = mysqli_fetch_assoc($result))
{
    //I suppose, you have date in mysql fomat
    $date = new DateTime($row['date1']);
    $row['date1'] = $date->format('d/m/Y');

    echo "<tr>";  
    ...
于 2013-06-30T17:03:51.563 に答える
0
    echo "<table cellspacing='1'><tr bgcolor='#fe0075'><th>Course Title</th><th>Course Date</th></tr>";

while($row    = mysqli_fetch_assoc($result))
  {
  echo "<tr>";
  echo "<td>" . $row['course_title'] . "</td>";
  echo "<td>" ."d-m-Y", strtotime($row['date1'])  . "</td>";
  echo "</tr>";
  }
echo "</table>";
于 2013-06-30T17:05:52.057 に答える