尝试按日期排序,但总是在我创建列“日期”并向其添加日期 NOT NULL 时,它将回显“0000-00-00”而不是日期。
然后我做了一些 SQL 更改
阅读文章后
CREATE TABLE `driptone`.`announces` (
`announcements` text,
`updated_at` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`created_at` DATETIME DEFAULT NULL,
PRIMARY KEY (created_at)
);
但现在当我提交时说
MySQL 问题:列数与第 1 行的值数不匹配
我做错什么了?
//error_reporting(0);
$announcements = $_POST['announcement'];
if (!empty($announcements)) {
if (strlen($announcements) > 10) {
$date = date("Y/m/d");
$sql="INSERT INTO announcements (message, date_time) VALUES ('$announcements,$date')";
if (!mysql_query($sql))
die('MySQL problem:'.mysql_error());
} else {
echo 'Need to be atleast 10 characters long';
}
} else {
echo 'Fields are empty';
}
$queryPerson = mysql_query("SELECT * FROM announces ORDER BY created_at DESC") or die(mysql_error());
while($row = mysql_fetch_assoc($queryPerson) ) {
echo $row['announcements'] . ' ' . $row['created_at'] . '<br /><br /><br />';
}