DATETIME & Now()
Hier is me query: (Let niet op de beveiliging, want die is er namelijk nog niet. Die bouw ik nog in.)
Code (php)
1
INSERT INTO questions (name, message, date) VALUES('".$_POST['Name']."', '".$_POST['Message']."', NOW())
En haal het op met:
Word dat niet gebruikt om het verschil in 2 verschillende datums uit te rekenen? Want dat heb ik niet nodig.
Hier de insert script:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
if($_POST) {
require_once('includes/DbConnector.php');
$connector = new DbConnector();
$query = "INSERT INTO questions (name, message, date) VALUES('".$_POST['Name']."', '".$_POST['Message']."', NOW())";
if ($result = $connector->query($query)) {
$msg = "Question placed, Please allow some time for a comment.";
} else {
$msg = "There was an error with your input.";
}
}
?>
if($_POST) {
require_once('includes/DbConnector.php');
$connector = new DbConnector();
$query = "INSERT INTO questions (name, message, date) VALUES('".$_POST['Name']."', '".$_POST['Message']."', NOW())";
if ($result = $connector->query($query)) {
$msg = "Question placed, Please allow some time for a comment.";
} else {
$msg = "There was an error with your input.";
}
}
?>
Hier de Select script:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
require_once('includes/DbConnector.php');
$connector = new DbConnector();
// Execute the query
$result = $connector->query('SELECT ID AS articleID, name, message, date FROM questions ORDER BY articleID');
// Get an Array with resultsd
// Loop for each item in that array
while($row = $connector->fetchArray($result)) {
echo '<div class="content">';
echo '<h1>' . $row['name'] . '<br /><span>'. $row['date'] . '</h1>';
echo '<b>Message:</b><br />';
echo $row['message'];
echo '</div>';
}
?>
require_once('includes/DbConnector.php');
$connector = new DbConnector();
// Execute the query
$result = $connector->query('SELECT ID AS articleID, name, message, date FROM questions ORDER BY articleID');
// Get an Array with resultsd
// Loop for each item in that array
while($row = $connector->fetchArray($result)) {
echo '<div class="content">';
echo '<h1>' . $row['name'] . '<br /><span>'. $row['date'] . '</h1>';
echo '<b>Message:</b><br />';
echo $row['message'];
echo '</div>';
}
?>
SELECT
ID AS articleID,
DATE_FORMAT(date, 'Y - m- d') as formatteddate,
name,
message,
date
FROM
questions
ORDER BY
articleID');
DATE_FORMAT(datetime, 'H:i:s d-m-Y') ?
Dit werkt trouwens niet, als ik dan formatteddate aan roep is de echo: Y-m-d, gewoon de text.
Gewijzigd op 01/01/1970 01:00:00 door Stefan