【发布时间】:2016-04-21 18:11:35
【问题描述】:
我正在尝试使用 PHP 进行 SQL 查询,以填充表单中的各个字段,以便站点管理员可以对其进行编辑。这两个字段是日期和时间。
我使用两种输入类型“日期”和“时间”。日期字段填充完美。时间字段将变为空白。两者的数据都来自同一个 SQL 查询。我希望它们都以每个字段的预期格式显示。 (我正在为此使用 Chrome,因为我知道并非所有浏览器都支持字段类型)。
//Queries
$pull_game = "select datetime, city, opponents.opponent_id, game_type, tourn_name, time, home_score, vis_score, day_of_week, month, day, year, parks.park_id, park, win, loss, tie, result from games, opponents, parks, tournaments where opponents.opponent_id = games.opponent_id and parks.park_id = games.park_id and tournaments.tourn_id = games.tourn_id and game_id= ".$_POST['game_id'] . ";";
$game_stats = mysqli_query($con,$pull_game) or die("ERROR: $pull_game. ".mysqli_error());
$game = mysqli_fetch_array($game_stats);
//Display data
<input type='date' name='date' value=<?= $game['datetime']?>>
<input type='time' name='time' value=<?= $game['datetime']?>>
我尝试删除日期字段以查看时间字段是否有效,但它仍然是空白的。我没有运气研究这个 - 我发现的大部分内容都是用日期时间数据更新数据库。我正在寻找相反的(有点)。
任何帮助将不胜感激。
【问题讨论】:
-
您要在其中填充完整的日期/时间字段?
yyyy-mm-dd hh:mm:ss不是有效的“时间”值,因此如果该字段为空白,请不要感到惊讶。 -
也缺少引号。