2012-06-03 2 views
0

안녕하세요 이것이 내 자신의 포럼을 구축하는 방법입니다. 그러나 이것이 어떻게 30-5-2012와 같은 데이터베이스에 "날짜"를 설정해야합니다.하지만 어떻게보아야합니까? 그것을 데이터베이스에서 꺼낼 때. 나는 MySQLI이처럼 구축덴마크어 시간/날짜로 다시 작성

여기

나는 데이터베이스에 위치 할 때 보이는 방법

<form action="#" method="post" name="formular" onsubmit="return validerform()"> 
      <?php 
      if ($stmt = $mysqli->prepare('INSERT INTO `forum` (`title`, `tekst`, `dato`, `id_brugere`) VALUES (?, ?, ?, ?)')) { 
      $stmt->bind_param('ssss', $title, $tekst, $dato, $id_brugere); 
      //fra input ting ting.. 
      $title = $_POST["title"]; 
      $tekst = $_POST["tekst"]; 
      $id_brugere = $_SESSION["user_id"]; 
      $dato = date('d-m-Y'); 

      $stmt->execute(); 
      $stmt->close(); 

      //er der fejl i tilgangen til table.. 
      } else { 
       echo 'Der opstod en fejl i erklæringen: ' . $mysqli->error; 
      } 
      ?> 
     <table border="0"> 
      <tr> 
       <td id="tb-w_a"><p>Title</p></td> 
       <td>:</td> 
       <td><input type="text" name="title"></td> 
      </tr> 
     </table> 
    <textarea name="tekst" style="width:716px; height:170px;"></textarea><br /> 
    <input type="submit" value="Opret indhold"> 
</form> 
다음

그것은 내가 데이터베이스 여기

<?php 
      if ($stmt = $mysqli->prepare('SELECT id_forum, title, tekst, dato, id_brugere FROM `forum` ORDER BY `forum`.`id_forum` DESC LIMIT 0 , 30')) 
      { 
      $stmt->execute(); 
      $stmt->store_result(); 
      $stmt->bind_result($id_forum, $title, $tekst, $dato, $id_brugere); 
      $count_res = $stmt->num_rows; 

      if($count_res > 0) 
      { 
      while ($stmt->fetch()) {  
      ?> 
      <tr class="forumtoppen"> 
      <td class="titleforum"><?php echo $title;?> - <a href="">L&#230;se mere</a></td> 
      <td>Dato: <?php echo $dato;?></td> 
      </tr> 
      <?php 
       } 
       } 
      else 
       { 
       ?> 
        <p>der er ingen overhovedet!.. hmm</p> 
       <?php 
       } 
      } 
      ?> 

밖으로을 때의 모습입니다 나는 이것을 덴마크의 시간으로 변환해야만한다.

<?php echo $dato;?> 

오류는 없지만 단지 덴마크어 날짜로 작성해야합니다.

답변

0

왜 검색 쿼리에서 mysql의 date_format 함수를 사용하지 않습니까? (php docs)

SELECT id_forum, title, tekst, date_format(dato,'%d-%m-%Y') as dato, id_brugere 
FROM `forum` 
ORDER BY `forum` . `id_forum` DESC LIMIT 0 , 30 
+0

작성한 내용을 복사하겠습니까? – user1433667

+0

쿼리를 실행하여 원하는대로 작동하는지 확인하십시오. 너의 것에서 만 변화는 dato 대신에 dat_format (dato, '% d- % m- % Y')이다. –

+0

http://imageshack.us/photo/my-images/232/assst.png/ – user1433667