使用 UNIX_TIMESTAMP 确定行的颜色
我目前有这样的代码:
$rawsql2 = "SELECT
*
FROM
_erc_foffices n
INNER JOIN
_erc_openings o ON n.id = o.branch_id
INNER JOIN
_erc_openings_times t ON o.id = t.opening_id
WHERE
(
n.id = %d
);";
$sql2 = sprintf($rawsql2, mysql_real_escape_string($id));
$result2 = mysql_query($sql2);
/*These if & while statements decide whether or not the information should be displayed. If no results are returned from the query above then an alternative message is shown.*/
if(mysql_num_rows($result2) > 0) {
$count=0;
$day = 1;
echo "<div class='timetable'><p>";
while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) {
if ($day=='1') { echo "<b>Sun - </b>";} else if ($day=='3') { echo "<b>Mon - </b>"; } else if ($day=='5') { echo "<b>Tue - </b>"; } else if ($day=='7') { echo "<b>Wed - </b>"; } else if ($day=='9') { echo "<b>Thu - </b>"; } else if ($day=='11') { echo "<b>Fri - </b>"; } else if ($day=='13') { echo "<b>Sat - </b>"; } else { echo "";}
if ($row["open"] == 0 && $row["close"] == 0) {
if ($day % 2 == 1) {
echo "closed";
}
}
else{
echo "" . substr($row["open"], 0, -3) . "-" . substr($row["close"], 0, -3) . " ";
if ($count % 2 !=0 ){ echo "<br/>"; } }
$count++;
$day++;
}
} else {
echo "Error";
}
它从数据库中提取时间表,然后以以下格式显示:
Sun - 08:00-12:30 13:30-16:30
周一 - 09:00-17:00 18:00-20:00 等
我现在想做的是,例如,如果当前说的是星期日,那么星期日行字体将为红色。这可能吗?
感谢您的帮助
I currently have this code:
$rawsql2 = "SELECT
*
FROM
_erc_foffices n
INNER JOIN
_erc_openings o ON n.id = o.branch_id
INNER JOIN
_erc_openings_times t ON o.id = t.opening_id
WHERE
(
n.id = %d
);";
$sql2 = sprintf($rawsql2, mysql_real_escape_string($id));
$result2 = mysql_query($sql2);
/*These if & while statements decide whether or not the information should be displayed. If no results are returned from the query above then an alternative message is shown.*/
if(mysql_num_rows($result2) > 0) {
$count=0;
$day = 1;
echo "<div class='timetable'><p>";
while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) {
if ($day=='1') { echo "<b>Sun - </b>";} else if ($day=='3') { echo "<b>Mon - </b>"; } else if ($day=='5') { echo "<b>Tue - </b>"; } else if ($day=='7') { echo "<b>Wed - </b>"; } else if ($day=='9') { echo "<b>Thu - </b>"; } else if ($day=='11') { echo "<b>Fri - </b>"; } else if ($day=='13') { echo "<b>Sat - </b>"; } else { echo "";}
if ($row["open"] == 0 && $row["close"] == 0) {
if ($day % 2 == 1) {
echo "closed";
}
}
else{
echo "" . substr($row["open"], 0, -3) . "-" . substr($row["close"], 0, -3) . " ";
if ($count % 2 !=0 ){ echo "<br/>"; } }
$count++;
$day++;
}
} else {
echo "Error";
}
which pulls a timetable from the database, and then display it in the format:
Sun - 08:00-12:30 13:30-16:30
Mon - 09:00-17:00 18:00-20:00 etc
What I want to do now, is if for example, the current say is Sunday, then the Sunday row font would be red. Is this possible?
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PHP 的本机日期时间格式是 unix 时间戳,因此您可以获取查询中检索到的值,并使用
date('w', $timestamp)
获取星期几值。它返回 0(星期日)到 6(星期六)范围内的值,您可以使用它来确定颜色。PHP's native date-time format is a unix timestamp, so you can take the value retrieved in your query, and get the day-of-week value with
date('w', $timestamp)
. That returns a value in the range of 0 (Sunday) to 6 (Saturday), and you can use that to determine a color.您还可以使用 DAYOFWEEK查询中的 mysql 函数:
SELECT *, DAYOFWEEK(your_column_name) as dw .....
You can also use DAYOFWEEK mysql function in your query:
SELECT *, DAYOFWEEK(your_column_name) as dw .....