我有一个带有许多时间戳的表,我使用以下查询检测到了最忙的时间
$query = 'SELECT hour(date) AS h FROM bike_main GROUP BY h ORDER BY count(*) DESC LIMIT 1';
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);并使用以下命令输出:
<h3 id="hour"><?php echo $row['h']; ?></h3>
<p>is the busiest hour</p>这只返回"17",我希望这个返回的是5-6 6PM我尝试过使用:
if ($('#hour').val() == '17') {
$(this).val('5 - 6PM');
} else {
console.log('hour not logged');
}控制台每次都会记录"hour not logged“,并且我的JS被包装在一个$(document).ready包装器中。
编辑:此问题已解决。我尝试使用的不是很长的if/else语句;
for (var hour = 1; hour < 13; hour++) {
var nextHour = hour+1;
if($('.hour').text() == hour) {
$(this).val(hour + '-' + nextHour + ' AM');
}
}但这似乎行不通。
发布于 2014-06-13 17:17:09
使用.text()而不是.val()
if ($('#hour').text() == '17') {
$('#hour').text('5 - 6PM');
} else {
console.log('hour not logged');
}发布于 2014-06-13 17:19:39
尝尝这个
if ($('#hour').text() == '17') {
$('#hour').text('5 - 6PM');
} else {
console.log('hour not logged');
}发布于 2014-06-13 17:23:38
您甚至可以使用http://us3.php.net/manual/en/function.date.php通过PHP获得格式化的日期/时间
$query = 'SELECT date FROM bike_main GROUP BY h ORDER BY count(*) DESC LIMIT 1';
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);在html中
<h3 id="hour"><?php echo date('ga', $row['date']); ?></h3>
<p>is the busiest hour</p>https://stackoverflow.com/questions/24201773
复制相似问题