gpt4 book ai didi

mysql - 允许用户从选择框中选择 SET time_zone

转载 作者:行者123 更新时间:2023-11-29 20:11:42 24 4
gpt4 key购买 nike

我已经尝试处理网站上的时区有一段时间了。我的网站包含运动时间表。我将比赛详细信息输出到表格中。

我正在尝试找出一种方法来允许用户选择(从填充有时区值(例如 GMT +1:00、GMT 2:00 等)的选择框中)他们所在的时区。用户选择时区,然后应更新比赛详细信息(时间戳字段)中的日期和时间值以反射(reflect)用户选择的时区。

我使用下面的代码来设置时区,它将日期和时间字段的时区更改为我在 SET 语句中正确使用的偏移量。

$DB->exec("SET time_zone='+0:00';");`

令我困惑的是,如何将 +0:00 更改为用户从选择框中选择的任何内容,而不是始终设置为“+0:00”。

我尝试了 if 语句,例如

if (offset = "+1:00") {
$DB->exec("SET time_zone='+1:00';");
}

但是,当我从选择框中选择 +1:00 并单击提交按钮时,URL 显示 offset=+1:00,但日期和时间字段的值不会更改以反射(reflect)时区更改if 语句,并且仅保留下面 SET 语句中的值

$DB->exec("SET time_zone='+0:00';");

我是否以正确的方式处理这件事?或者我可以使用其他方法吗?我还想,当按下提交按钮时,输出将被放入 URL 字符串而不是 SET time_zone 语句中。有没有办法让按钮在单击时将 SET 语句的值更改为从下拉框中选择的偏移量?

下面是我的 HTML 和 PHP 代码

Config.php(用于数据库连接)

<?php
error_reporting( E_ALL & ~E_DEPRECATED & ~E_NOTICE );

define('DB_DRIVER', 'mysql');
define('DB_SERVER', '*******');
define('DB_SERVER_USERNAME', '****"');
define('DB_SERVER_PASSWORD', '*****"');
define('DB_DATABASE', 'sportsch_sport');


define('PROJECT_NAME', 'SportSchedule Easy Sports Schedules');
$dboptions = array(
PDO::ATTR_PERSISTENT => FALSE,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);

try {
$DB = new PDO(DB_DRIVER.':host='.DB_SERVER.';dbname='.DB_DATABASE, DB_SERVER_USERNAME, DB_SERVER_PASSWORD , $dboptions);
$DB->exec("SET time_zone='+0:00';");

} catch (Exception $ex) {
echo $ex->getMessage();
die;
}



?>

Index.php(主页,用户可以通过此页面上的搜索框按团队搜索,默认情况下它将显示数据库中的所有匹配项)

<?php
date_default_timezone_set('Europe/London');
echo date('Y-m-d H:i:s');
include './config.php';
include './header.php';

if (offset = "+1:00") {
$DB->exec("SET time_zone='+1:00';");
}

try{
$keyword = trim($_GET["keyword"]);
if ($keyword <> "" ) {
$sql = "SELECT f.hometeam, f.versus, f.awayteam, f.sport, f.competition, f.dateandtime,
Group_concat(s.name SEPARATOR ',') name,
Group_concat(x.channelid_fc SEPARATOR ',') channelid_fc
FROM footballfixtures f
LEFT JOIN fixturechannels x
ON x.matchid_fc=f.matchid
LEFT JOIN satellite s
ON x.channelid_fc=s.channelid
WHERE " . " (hometeam LIKE :keyword)
OR awayteam LIKE :keyword
OR competition LIKE :keyword
GROUP BY f.hometeam, f.versus, f.awayteam, f.sport, f.competition, f.dateandtime,
ORDER BY f.dateandtime ";
$stmt = $DB->prepare($sql);

$stmt->bindValue(":keyword", $keyword."%");


} else {

$sql = "SELECT f.hometeam, f.versus, f.awayteam, f.sport, f.competition, f.dateandtime,
Group_concat(s.name SEPARATOR ',') name,
Group_concat(x.channelid_fc SEPARATOR ','). channelid_fc
FROM footballfixtures f
LEFT JOIN fixturechannels x
ON x.matchid_fc=f.matchid
LEFT JOIN satellite s
ON x.channelid_fc=s.channelid
GROUP BY f.hometeam, f.versus, f.awayteam, f.sport, f.competition, f.dateandtime
ORDER BY f.dateandtime";

$stmt = $DB->prepare($sql);
}

$stmt->execute();

} catch (Exception $ex) {
echo 'Error loading match data';
}




?>
<html>

<head>
<script src="css/footable.filter.js"></script>

</head>
<body>

<div class="container mainbody">
<div class="mainpagetitle">
<h11>Sports Schedule</h11> <br> <br>
<p>We aim to provide you with sports schedule in an easy to view format</p> <br> <br> <br>
<form class="form-inline">
</div>


<div class="clearfix"></div>

<div class="col-xs-12">
<img src="css/tv3.png" class="img-responsive" />

<div id=class="container-fluid">
<div class="row">
<h2>Whats On Today</h2> <br>
<p> All todays matches/events are displayed below, you can search by team/player or competition/event using the search box. If you want to filter by sport, please select the sport name from the select box and filtered results will be displayed. </p>

<br>
<br>
<br>
<br>
</div>
</div>
</div>



<div class="searchform">
<form action="index.php" method="get" >
<label class="col-xs-12" for="offset";>
<select name="offset" id="offset">
<option value="+1:00">+1:00</option>
<option value="+2:00">+2:00</option>
<option value="+3:00">+3:00</option>
<option value="+4:00">+4:00</option>
</select>

</label>
<button class="btn btn-info">search</button>
</form>

</div>






<div class="searchform">
<h2> Search </h2>
<form action="index.php" method="POST" >
<label class="col-xs-12" for="keyword";>
<input type="text" value="<?php echo htmlspecialchars($_POST["keyword"]); ?>" placeholder="Enter Team or Competition" id="" class="form-control" name="keyword">
</label>

<button class="btn btn-info">search</button>
</form>
</div>





<div class="clearfix"></div>



<div class="searchform2">

<p> Select Sport Below to Display Events</p>
<div class="dropbox1">
<input type="hidden" id="filter" type="text"></input>
<select class="filter-status">
<option> </option>
<option value="aussierules">Aussie Rules</option>
<option value="basketball">Basketball</option>
<option value="boxing">Boxing</option>
<option value="football">Football</option>
<option value="gaelic">Gaelic Sports</option>
<option value="handball">Handball</option>
<option value="icehockey">Ice Hockey</option>
<option value="mma">MMA</option>
<option value="motorsports">Motorsports</option>
<option value="rugbyleague">Rugby League</option>
<option value="rugbyunion">Rugby Union</option>
<option value="tennis">Tennis</option>
<option value="volleyball">Volleyball</option>

</select>
</div>
<div class="clearlinks">
<a class="clear-filter" href="#clear" title="clear filter">. [clear]</a>
</div>
</div>
<div class="container">
<div class="row">
<div class="tables">
<div class="col-xs-12">
<table class="table table-hover footable" data-filter="#filter" data-filter-text-only="true">
<thead>
<tr>
<th>Home Team</th>
<th> vs </th>
<th>Away Team</th>
<th data-hide="phone, tablet">Sport</th>
<th data-hide="phone, tablet">Competition</th>
<th data-hide="phone, tablet"> Date and Time</th>
<th data-hide="phone, tablet">Channels</th>
</tr>
</thead>

<?php

if($stmt->rowCount() >0) {

while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{


$hometeam = $row['hometeam'];
$versus= $row['versus'];
$awayteam= $row['awayteam'];
$sport= $row['sport'];
$competition = $row['competition'];
$dateandtime=$row['dateandtime'];
$name=explode(',', $row['name']);
$channelid=explode(',', $row['channelid_fc']);

?>
<tbody>
<td> <?php echo $row[hometeam] ; ?> </td>
<td> <?php echo $row[versus] ; ?> </td>
<td> <?php echo $row[awayteam] ; ?> </td>
<td> <?php echo $row[sport] ; ?> </td>
<td> <?php echo $row[competition] ; ?> </td>
<td> <?php echo $row[dateandtime] ; ?> </td>

<td>
<?php for ($i = 0; $i < count($channelid) && $i < count($name); ++$i) {
$achannelid = $channelid[$i];
$aname = $name[$i];

//here the code you wanted
echo "<a href='http://sportschedule.xyz/view_channels.php?channelid=" .$achannelid."'> ".$aname." </br> </a> ";

}

?>

非常感谢任何人提供的任何帮助或建议或任何阅读本文的人。

最佳答案

找到了解决办法

if (isset($_GET['offset'])) { 
$os = $_GET['offset'];
if ($os >= "1" && $os < "5" && (strlen($os)==1) ) { // basic attempt at sanitising the input
$DB->exec("SET time_zone='+" . $os . ":00';");
}
}

关于mysql - 允许用户从选择框中选择 SET time_zone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40063014/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com