2014-11-25 2 views
0

간단한 문제가 있습니다. 이전에 CURDATE()를 사용했지만 MSSQL이 지원하지 않기 때문에 작동하지 않았습니다. MySQL만이 GETDATE()를 추가했으나 작동하지 않습니다. 현재 날짜를 어떻게 알 수 있습니까? 나는 id와 오늘 날짜에 의해서만 이름 순서를 보여주기를 원합니다. CURDATE()가 MSSQL에서 작동하지 않습니다. 무엇을 대체 할 수 있습니까?

$stmt = $db->prepare("SELECT * FROM students WHERE name='Firstname' And Getdate() ORDER BY id DESC"); 
$stmt->execute() 

이 내가
$stmt = $db->prepare("SELECT * FROM students WHERE name='BOB' And Getdate() ORDER BY id DESC"); 
    $stmt->execute() 

전체 쿼리 페이지

을 의미하는 것입니다 미안 업데이트되었습니다. 여기

<head> 

    <title></title> 
    </head> 
    <body> 
    <?php 
    //connects to the database 
    require_once("../../db_connect.php"); 

    //prepared statement with PDO to query the database 
    $stmt = $db->prepare("SELECT * FROM requests WHERE name='Bob' AND Date = CAST(GETDATE() AS DATE) ORDER BY id DESC"); 
    $stmt->execute(); 

    ?> 

    <?php //start of the while loop ?> 
    <?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { ?> 

<table border="1"> 

    <br> 
    <tr> 
     <th style="width:25px; height: 25px;">ID</th> 
     <th style="width:90px; height: 25px;">Name</th> 
     <th style="width:40px; height: 25px;">Date</th> 

    </tr> 
    <tr style="width:25px"> 
    <?php $id = $row['id'];?> 
    <?php echo "<td> <a href='../../update.php?id=$id'>$id</a></td>"?> 
     <td style="width:90px; height: 12px;"><?php echo $row['name']; ?></td> 
     <td style="width:40px; height: 12px;"><?php echo $row['date']; ?></td> 

    </tr> 

    </table> 

     <?php } //end of the while loop?> 
    </body> 

</html> 

페이지는 사용자가 정보를 업데이트했다입니다

<?php 
    include('db_connect.php'); 
    $id=$_GET['id']; 
    $result = $db->prepare("SELECT * FROM students WHERE id= :id"); 
    $result->bindParam(':id', $id); 
    $result->execute(); 
    for($i=0; $row = $result->fetch(); $i++){ 
?> 

<html> 
<head> 
<title></title> 


</head> 
<body class='body'> 
<form action = "update_process.php" method ="post" class="Form"> 

<p><input type ="hidden" name = "id" value="<?php print($id); ?>"</p> 

<table border='1' align="center"> 
<tr>  
    <td>Name:</td> 
<td><input type="text" value ="<?php print($row['name']) ?>"name="name"></td> 
</tr> 

<tr>  
    <td>Date</td> 
<td style="width: 303px"> 
<input type="text" value ="<?php echo date("Y-m-d",time())?>"name="date" style="width: 148px"></td> 


</tr> 

</table> 

<input type="submit" value= "Update Information"> 
<br> 
</div> 
</form> 


</body> 
</html> 
<?php 
    } 
?> 
+0

'cast (getdate() as date'. 그러나'where' 절은 의미가 없습니다. 그것은 일종의 비교가 필요합니다. –

답변

1

이 MySQL의에서 CURDATE()에 맞게 SQL 서버에 상응하는 기능이 없습니다하지만 당신은 GETDATE()DATE 날짜 형식을 캐스팅하여 모방 할 수 (시간 성분을 줄무늬로 함) :

CAST(GETDATE() AS DATE) 

H 그러나 귀하의 SQL 문이 여전히 이해가 안되면 다음과 같이 테이블의 열과 날짜를 비교할 의향이 있다고 생각합니다 :

+0

이 오류가 발생합니다 데이터 형식 텍스트와 날짜가 같음 연산자에서 호환되지 않습니다. 날짜가 자동으로 채워진 텍스트 상자가 있습니까? Veronica

+0

날짜가 db와 같이 변경됨 2014-11-25 – Veronica

+0

날짜는 어디로 이동합니까? – DavidG

관련 문제