所以我有这段代码在表格中填写我的出价列表的结果:
$query = "SELECT item, start_time, start_date, description, price FROM items";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo"<tr><td>$row[item] </td>";
echo" <td> $row[price]</td>";
echo" <td> $row[description]</td>";
echo"<td> $row[start_time]</td>";
echo"<td> $row[start_date]</td>";
}
但是,我想添加另一列“状态”,根据用户定义的“start_time”和“start_date”值与今天的时间和日期的比较,显示出价的有效或无效状态。我该怎么办? MySQL中'start_time'和'start_date'的当前数据类型是时间和日期。感谢。
答案 0 :(得分:0)
假设您的数据库列设置为时间戳,您可以通过两种方式执行此操作。我绝对同意你应该在数据库中使用时间戳的评论。与将UNIX时间戳保存为整数相比,它的数据密集程度更低,并且不难从sql中获取日期。
1)在你的sql SELECT中,你可以添加如下内容:
DATE_FORMAT( `scheduled_release`, \'%m-%d-%Y\') AS formattedDate
Select `name`, DATE_FORMAT( `scheduled_release`, \'%m-%d-%Y\') AS formattedDate WHERE id = ?
2)date("m/j/y", strtotime( $row[date ) );